How to get all filtered items of grids in vaadin 8

I had filter for the grid, there is ListDataProvider created for it.

Is there a method to get all filtered items?

The DataProvider.getItems() return all data in the grid instead of filtered data.

Thank you!

Hi, this is a frequently asked question.

You should use Grid.getDataCommunicator().fetchItemsWithRange(…) instead. It will return the items after filtering and sorting.

https://vaadin.com/api/framework/8.6.0/com/vaadin/data/provider/DataCommunicator.html#fetchItemsWithRange-int-int-

I don’t think this will work.
Why do I need to fetch items?

And also, where does this communicator come from?

Got it, I was still using Vaadin 8.1.0, I tried all version after 8.4.0, it has bug on tree selection.
But it looks like 8.3 works fine.
I used getDataCommunicator().fetchItemsWithRange(0, this.getRowCount()), it get correct filtered data.

Thanks!

Yes, it was private until 8.2.0. There has been lot of bug fixes in framework recently, I recommend to go 8.6.0.

Note, getDataCommunicator().fetchItemsWithRange(0, this.getRowCount()) is handy, but there is a caveat. If this.getRowCount() is big, this may be costly operation.

The tree selection has bug after 8.3.3, all version after that the tree selection won’t work very well.

Thanks for informing, this should be investigated more. Could you describe the bug in more detail. Preferably we would like to get small test application and description with steps to reproduce the issue, then a report to our issue tracker can be added github.com/vaadin/framework/issues

how to do this in vaadin 13?

Tatu Lund:
Yes, it was private until 8.2.0. There has been lot of bug fixes in framework recently, I recommend to go 8.6.0.

Note, getDataCommunicator().fetchItemsWithRange(0, this.getRowCount()) is handy, but there is a caveat. If this.getRowCount() is big, this may be costly operation.

8.5.2, 8.6.2, 8.8.0 has no method getRowCount for Grid.
Or this.getRowCount() mean’s something else?

8.5.2, 8.6.2, 8.8.0 has no method getRowCount for Grid. Or this.getRowCount() mean’s something else?

Hmm, looks like I copied from some of my apps. One thing you can use is grid.getDataCommunicator().getDataProviderSize()

how to do this in vaadin 13?

At the moment the equivalent method is protected in Vaadin 13, discussion is ongoing to have something suitable in V14, but not confirmed

https://github.com/vaadin/flow/issues/4510

Tatu Lund:

8.5.2, 8.6.2, 8.8.0 has no method getRowCount for Grid. Or this.getRowCount() mean’s something else?

Hmm, looks like I copied from some of my apps. One thing you can use is grid.getDataCommunicator().getDataProviderSize()

how to do this in vaadin 13?

At the moment the equivalent method is protected in Vaadin 13, discussion is ongoing to have something suitable in V14, but not confirmed

https://github.com/vaadin/flow/issues/4510

I think it is important to resolve as soon as possible for Vaadin Flow. Having this method is basic for handling grids