viritin / flow-viritin

Viritin inspired project for Vaadin Flow

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PagingGrid#setPagingDataProvider triggers a pageRequested call on the data provider

jorgheymans opened this issue · comments

PagingGrid#setPagingDataProvider does this:

    public void setPagingDataProvider(PagingGrid.PagingDataProvider<T> provider) {
        this.dataProvider = provider;
        preparePaginationBar();
        setItems(dataProvider.pageRequested(0, getPageSize()));
    }

The call to setItems is perhaps a bit suprising, and leads to double fetching of the data in the case where you want the grid to have a default sort column. For this one needs to call sort() on the grid, after the data provider has been set.

Thinking aloud, should it maybe postpone the call to be done just before "rendering" (~ the beforeClientRequest thingie) 🤔

Thanks, for the moment we got around it by delaying the setItems call in our PagingDataProvider itself. I was looking at Grid as well, and there they also call setItems when the BackendDataProvider is set in the constructor, but the difference is that the this data provider already has the sorting built into it whereas PagingDataProvider does not.

I made a tiny enhancment, which may be enough 🤔 The sort method can now be called before setting the data. What do you think, is that good enough?

That should work as well yes. Given that the api allows to sort before a dataprovider is set, the fix makes sense either way.

The fix is working for us, thanks!