Crud filtering with my own filter fields

I have a Crud, which uses a CrudGrid that I set up and configure manually, with my own filter fields in the column headers.

The CrudGrid used to be a normal Grid before my current refactoring, and it used a ListDataProvider where I could reset the filter on the fly when a value of a filter input field has changed. I did this like so:

// method called at value change of any filter field
private void onFilterChange(){
    ListDataProvider<Foo> dataProvider = (ListDataProvider<Foo>) grid.getDataProvider();
    dataProvider.setFilter((item) -> {
		boolean firstNameMatch = item.getFirstName().contains(firstNameFilterField.getValue());
		boolean lastNameMatch = item.getLastName().contains(lastNameFilterField.getValue());
		boolean fooBarEnumMatch = item.getFooBarEnum().equals(fooBarEnumFilterField.getValue()); 
		return firstNameMatch && lastNameMatch && fooBarEnumMatch;
	}
}

But now that my grid has a CrudDataProvider, I can no longer call setFilter.

I can see in the method CrudGrid::setupFiltering how the default filters would be set up. But they will all be TextFields - I want to have some ComboBoxes as well to filter enum fields, or using equals instead of contains for some columns, etc.

How can I set up my own filters in a CrudGrid?

I am now setting up the value change listeners of my filter fields the same way as the default filters would be set up:

public static TextField singleFilterTextField(String placeholder, String columnKey, CrudGrid grid){
    TextField filter = new TextField();
    filter.setPlaceholder(placeholder);
    filter.setValueChangeMode(ValueChangeMode.EAGER);
    filter.setWidth("100%");
    filter.addValueChangeListener(valueChangeEvent -> {
        grid.getFilter().getConstraints().remove(columnKey);
        if(!filter.isEmpty()){
            grid.getFilter().getConstraints().put(columnKey, valueChangeEvent.getValue());
        }
        grid.getDataProvider().refreshAll();
    });
    grid.getColumnByKey(columnKey).setHeader(filter);
    return filter;
}

When debugging I can see that the constraints list of the CrudFilter are being filled up as expected. But the grid is not being filtered as result.
All that happens is I get many many many log warnings:
[WARN ] com.vaadin.flow.server.communication.rpc.AbstractRpcInvocationHandler - Got an RPC for non-existent node: 1906

I have also tried using column keys that match the respective property name exactly, that did not help.

I need help please

Hi Kaspar,

It seems it should work. Can you provide a more complete example, including the DataProvider?

I saw that my implementation of fetchFromBackEnd in the dataprovider did not filter the stream based on query.getFilter() as shown in the [example code]
(https://vaadin.com/components/vaadin-crud/java-examples) (PersonDataProvider). Of course the filtering didn’t work like this. It works now, sorry for the bother.