Vaadin 23: Filtering ListDataProvider unexpected behaviour

I am experiencing weird behaviour with my filtering implementation
Essentially I have a textfield from which I want to filter a list of buttons depending on their displayName.
Atm it’s just super simple, I am filtering with String.startsWith.

For that to work, I implemented it so that on every ValueChangeEvent of the searchBarField I am re-setting the filter
in the ListDataProvider.

The JiraOptionListElement::getDisplayNameForFiltering returns a displayName.toLowerCase(); String

My code:

TextField searchBarField = new TextField("Search bar");
searchBarField.setValueChangeMode(ValueChangeMode.ON_CHANGE);
this.jiraOptionsDataProvider =  DataProvider.ofCollection(options); // ListDataProvider

searchBarField.addValueChangeListener(event ->  {
    log.trace("Change Event");
    log.trace("Value of textfield event[{}]", event.getValue().toLowerCase());

    jiraOptionsDataProvider.setFilter(JiraOptionListElement::getDisplayNameForFiltering, displayName -> {
        log.trace("element displayname [{}]", displayName);
        return displayName.startsWith(event.getValue().toLowerCase());
    });

});

jiraOptionList.setDataProvider(jiraOptionsDataProvider); // Virtual List of JiraOption Elements
jiraOptionList.setRenderer(jiraOptionListRenderer);

Thanks for any help in advance :heart:

At the start it looks like this. It correctly displays all current options
image.png

When I type “C” in the field, I would expect it to find the Custom Field but the List turns out to be empty
image.png

Now when I clear the searchbar again, the list comes back but the Custom Field is not there.
image.png

If I try to do the same with Issues, I type in “Iss” in the search field, the filter lets all the elements through I’d expect
image.png

Any ideas what the issue is? :face_holding_back_tears:

You at least need an if statement

If field / value is empty
removeFilters
else
setFilter

Updated the value change listener like this. The behaviour stays the same sadly

test.addValueChangeListener(event ->  {
    log.trace("Change Event");
    log.trace("Value of textfield event[{}]", event.getValue().toLowerCase());
    if(event.getValue().isBlank()) {
        jiraOptionsDataProvider.clearFilters();
    }
    else {
        jiraOptionsDataProvider.setFilter(JiraOptionListElement::getDisplayNameForFiltering, displayName -> {
            log.trace("element displayname [{}]", displayName);
            return displayName.startsWith(event.getValue().toLowerCase());
        });
    }
});```

Exactly the same? That hard to believe :sweat_smile:

No, it really is the same, whichi is why I’m really confused

image.png
image.png
image.png

I think this is an issue with the first element of the list

as the other elements do not have that issue