I updated vaadin 7 grid to vaadin8 Grid. I follow the vaadin 8 tutorial and set values to grid by grid.setItems(mylist),
that is working fine. Now I want to apply multiple filters to grid By using HeaderRow and HeaderCell.
Instead of dataProvider.setFilter, you can use dataProvider.addFilter to add more filters to the DataProvider (they are logically AND filters). setFilter will override any previous filters.
But by replacing setFilter with addFilter in the given code, he will just end up adding more and more filters with each value change. If he writes “test” in the filter field, the valueChangeListener will add a Filter for “t”, and one for “te” and one for “tes” and one for “test”. You would need additional buttons to clearFilters() etc. because otherwise there is now no way to filter for something different (even if you change the filterfield value to “foobar”, the previous filters (“t”, “te”, “tes”, “test”) remain active.
I would do it this way:
declare all filter fields as a private field in order to access them later
for every filter field, add the same ValueChangeListener, which will take all filter values into account when it sets the new filter (with setFilter! let only one filter be active at any time but let that filter include all values you want to filter by)
Now, I have not tested this code but I hope it helps with understanding what I mean. (Edit: I tested it and it works perfectly in Vaadin 13. I believe it is the very same code in Vaadin 8)
Important: Make sure that your filter fields have the valueChangeMode set to EAGER, or else in the onFilterChange the field will still have outdated value.