Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilterablePageableDataProvider does not work in Vaadin Bakery demo #23

Open
jcgueriaud1 opened this issue Aug 20, 2020 · 2 comments
Open

Comments

@jcgueriaud1
Copy link

If you try to filter the combobox in the order editor in the Bakery Demo. The combobox is not filtered.

If you add a breakpoint in FilterablePageableDataProvider in fetch(Query<T, F> query).

The query filter is set but it's ignored.

 private Query<T, F> getFilterQuery(Query<T, F> t) {
        return new Query(t.getOffset(), t.getLimit(), t.getSortOrders(), t.getInMemorySorting(), this.filter);
    }

filter_null

query_filter_not_null

See the forum post here: https://vaadin.com/forum/thread/18354860/combo-boxes-not-filtering-as-expected

@jcoleman-scott
Copy link

jcoleman-scott commented Aug 26, 2020

In my use case the filter is empty. It appears the ComboBox doesn't pass it at all; I assume this is because the ComboBox has been set up to do client-side filtering based on how it was constructed?

@jcgueriaud1
Copy link
Author

The combobox never called setFilter of the FilterablePageableDataProvider and FilterablePageableDataProvider does not use the query filter given by the combobox.
If you change the FilterablePageableDataProvider to this:

package org.vaadin.artur.spring.dataprovider;

import com.vaadin.flow.data.provider.Query;
import java.util.Optional;
import java.util.stream.Stream;

public abstract class FilterablePageableDataProvider<T, F> extends PageableDataProvider<T, F> {
    private F filter = null;

    public FilterablePageableDataProvider() {
    }

    public void setFilter(F filter) {
        if (filter == null) {
            throw new IllegalArgumentException("Filter cannot be null");
        } else {
            this.filter = filter;
            this.refreshAll();
        }
    }

    public int size(Query<T, F> query) {
        return super.size(this.getFilterQuery(query));
    }

    public Stream<T> fetch(Query<T, F> query) {
        return super.fetch(this.getFilterQuery(query));
    }

    private Query<T, F> getFilterQuery(Query<T, F> t) {
       /// Use the query filter if it exists else use the external filter
        F filter = t.getFilter().orElse(this.filter);
        return new Query(t.getOffset(), t.getLimit(), t.getSortOrders(), t.getInMemorySorting(), filter);
    }

    protected Optional<F> getOptionalFilter() {
        return this.filter == null ? Optional.empty() : Optional.of(this.filter);
    }
}

The filtering is working.

I'm not sure if my fix is the right one, but I think the problem is not related to the combobox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants