Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 4.0.1
* String are now matched NOT case-sensitive
* Search bar now uses lazy value change mode

# 4.0.0
* Added new component `GridFilterWithSearchBar`
* Has a search bar for quick searching of strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected void onFilterUpdate()
this.fireEvent(new FilterChangedEvent<>(this, false));
}

protected void applyFilterToGrid()
public void applyFilterToGrid()
{
this.applyFilter.accept(this.grid, this.filterContainerComponent.getFilterComponents());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
Expand All @@ -27,6 +28,7 @@
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.value.ValueChangeMode;


public class GridFilterWithSearchBar<T> extends GridFilter<T>
Expand Down Expand Up @@ -56,11 +58,11 @@ protected GridFilterWithSearchBar(

this.withApplyFilter((gr, components) -> {

final String searchBarValue = this.txtSearchBar.getValue();
final boolean hasSearchBarValue = searchBarValue != null && !searchBarValue.isEmpty();
final Optional<String> optSearchBarValue = this.getSearchBarValue()
.map(s -> s.toLowerCase(Locale.ROOT));

gr.getListDataView().setFilter(item ->
(!hasSearchBarValue || this.doesItemMatchAnySearchBarExtracted(item, searchBarValue))
optSearchBarValue.map(v -> this.doesItemMatchAnySearchBarExtracted(item, v)).orElse(true)
&& components.stream().allMatch(c -> c.test(item)));
});

Expand All @@ -85,6 +87,7 @@ protected void initUIWithSearchBar(final boolean hideDetailsFilterInitially)
protected void initSearchBar(final boolean hideDetailsFilterInitially)
{
this.txtSearchBar.setPlaceholder("Search...");
this.txtSearchBar.setValueChangeMode(ValueChangeMode.LAZY);
this.txtSearchBar.setWidthFull();
this.txtSearchBar.addValueChangeListener(ev -> this.onFilterUpdate());

Expand Down Expand Up @@ -116,6 +119,7 @@ protected boolean doesItemMatchAnySearchBarExtracted(final T item, final String
return this.searchBarValueExtractors.stream()
.map(func -> func.apply(item))
.filter(Objects::nonNull)
.map(s -> s.toLowerCase(Locale.ROOT))
.anyMatch(s -> s.contains(value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public boolean canHandle(final Class<?> clazz)
@Override
public boolean test(final Object input, final SingleValue<Object> filterValue)
{
if(input instanceof final String inputString
&& filterValue.getValue() instanceof final String filterValueString)
{
return inputString.equalsIgnoreCase(filterValueString);
}

return Objects.equals(input, filterValue.getValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public FieldFilterConditionComponent(
this.operationDetailsContainer.addClassNames(FilterFieldConditionComponentStyles.DETAILS);

this.getContent().add(this.cbField, this.cbOperation, this.operationDetailsContainer);
this.getContent().setAlignItems(FlexComponent.Alignment.BASELINE);
this.getContent().setAlignItems(FlexComponent.Alignment.CENTER);
this.getContent().addClassNames(
FilterComponentStyles.FILTER_COMPONENT,
FilterFieldConditionComponentStyles.FILTER_FIELD_CONDITION_COMPONENT);
Expand Down