Vaadin 8: Combobox and Dataprovider with Filtering?

Hey guys,

has anyone an example how to use a Combobox with a Dataprovider, which uses the Input from combobox as Filtering?
I read this
https://vaadin.com/docs/-/part/framework/components/components-combobox.html#components.combobox.filtering
but i do not realy understand how to use
setItems(CaptionFilter, Collection)

a quick example would be realy nice.

Best regards

after more Try&Catch i have a first solution found my own way.

    private ComboBox<EveItemDto> getFilterCombo() {
        if(filtercombo == null){
            filtercombo = new ComboBox<>("Search EVE Item");
            filtercombo.setWidth(100, Unit.PERCENTAGE);
            filtercombo.setEmptySelectionAllowed(true);
            filtercombo.setEmptySelectionCaption("Search for an Item ...");
            filtercombo.setItemCaptionGenerator(EveItemDto::getTypeName);
            filtercombo.setItemIconGenerator((EveItemDto item) -> {
                if(item.getIconFile() != null && !item.getIconFile().isEmpty()){
                    return new ThemeResource(item.getIconFile());
                }
                else{
                    return new ThemeResource(EMPTY_ICON);
                }
            });
            
            filtercombo.setDataProvider((String filter, int offset, int limit) -> {
                if(filter.isEmpty() == false){
                    return presenter.getFoundDatas().stream();
                }
                else{
                    return presenter.getEmptyList().stream();
                }
            }, (String value) -> {
                if(value.isEmpty() == false){
                    return presenter.findEveItems(value);
                }
                else{
                    return presenter.getEmptyList().size();
                }
            });
            
        }
        return filtercombo;
    }

But are there better ways? or is this correct?
How can i manipulate the limit value?

Hmm. Java 8 lambdas are nice but perhaps a concrete filter class on the dataprovider would be more useful in this case? If you hold a reference to it, you can change the parameters that affects the filtering, I would think.

hey nicklas,

sound logical. i will give it a try. at all this was my first usable result :wink: