How to apply multiple filters to Vaadin 8 Grid

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.

    public void addSerachFilters(final Grid<myclass> grid, HeaderRow filterRow){
	for(final Column<myclass, ?> col: grid.getColumns()){
		HeaderCell cell=filterRow.getCell(col);
		if(col==null)
			continue;
		filterField= new TextField();
		filterField.setData(col);
		filterField.setId(col.getCaption());

        filterField.addValueChangeListener(this::onNameFilterTextChange);

		cell.setComponent(filterField);

	}
}

private void onNameFilterTextChange(HasValue.ValueChangeEvent<String> event) {
		ListDataProvider<myclass> dataProvider = (ListDataProvider<myclass>) detailsTable.getDataProvider();			
	    dataProvider.setFilter(myclass::getName, s -> caseInsensitiveContains(s, event.getValue()));
	 
}

private Boolean caseInsensitiveContains(String where, String what) {
        return where.toLowerCase().contains(what.toLowerCase());
    }

i follwed above way that is working for only one column filter ,i want to multiple filters
is it possible in one method to get multiple filters.

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:

  1. declare all filter fields as a private field in order to access them later
  2. 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)
private void onFilterChange(HasValue.ValueChangeEvent<String> event){
	ListDataProvider<myclass> dataProvider = (ListDataProvider<myclass>) detailsTable.getDataProvider();			
	dataProvider.setFilter((item) -> {
		boolean nameDoesMatch = item.getName().contains(nameFilterField.getValue());
		boolean addressDoesMatch = item.getAddress().contains(addressFilterField.getValue());
		
		return nameDoesMatch && addressDoesMatch;
	});
}

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.

how to export vaadin8 grid data to Excel

Have you tried https://vaadin.com/directory/component/exporter ?

There are add-ons that can do this. Here are two: [Excel exporter]
(https://vaadin.com/directory/component/excel-exporter) and [Exporter]
(https://vaadin.com/directory/component/exporter)

ListDataProvider dataProvider = (ListDataProvider) detailsTable.getDataProvider();

How to get values from dataprovider.
I tried dataProvider.getItems()
but not geeting Exact results.
I want to get Exact data from dataprovider.