Grid (Vaadin 8) has no function to ask for the complete number of data rows.
We need such a function to visualize the row count of the Grid.
Optional Filters should be taken into account.
see https://vaadin.com/forum#!/thread/15252122
Hi Matti,
thanks for the patch.
if I have read the patch right, the new size() function does not return the filtered number of rows but the complete amount of rows of the DataProvider without filtering. This could not be the visible count of rows.
public int size() { return getDataProvider().size(new Query<>()); }
I would need the filtered, actual visible amount of rows from the Grid. I do not know, whether a size() function, which does not take the filter into account, would be that usefull.
Alex
Very good point @aley2003 , and there are also other implications too with the version in the PR, discussed in there. I'll do another fix for this tomorrow.
This proved a lot more complex and is on hold for now. The main issue is:
Grid<String> grid = new Grid<>();
grid.setItem("foo","bar");
grid.size(); // would not return 2
Also Matti's approach of doing a new size query for each grid.size() call would not reflect the actual size of grid either, since the data provider size can have changed but the grid doesn't necessarily know this. And it was also lacking the filtering information.
That is why I propose that there should instead be an event that is fired each time when the size of the data is changed.
As a developer I just want to get the size of the grid, I don't care if it causes an extra query at some point and in most common use cases (in memory container) the size is correct. I hope you are not trying to make this too "academic". Simple things should be simple.
@mstahv I'm just trying to make it _correct_. I'm not going to add any feature that is broken from the beginning. Doing a size query reports the size of the backend at that moment, not the amount of rows in the grid.
Doing grid.getDataProvider().size(new Query<>()); is something that anyone can do, but that may not return the same amount of rows that is actually in the grid if there has been changes. If they know that this is fine, then they can do it. Since grid doesn't have its own filtering, the developer should have the filter available anyway and can apply that to the query.
As a developer, I want to have two methods for (List)dataProvider:
In addition, one could have access to actual filtered item list e.g. getFilteredItems()
This would really simplify things
Thanks
So I have been using this static helper method I made for a while now and I can say from my experience it does report the number of filtered items from a grid:
public static final void updateCaption(Grid grid){
grid.setCaption(
grid.getCaption()
.replaceFirst("\\{\\}", "0")
.replaceFirst("\\d+",
String.valueOf( grid.getDataProvider().size(new Query<>()))));
}
That being said I also have a whole, hand coded binder-esque class that handles filtering (builds the fields too).
I will say that if you are using ListDataProviders for the grid then:
grid.getDataProvider().size(new Query<>())
will report the correct number for filtered Items.
Example:

filterSelect.addValueChangeListener(e->GridUtil.updateCaption(grid));

Now as for non-ListDataProviders, I will have to look into more.
Hello there!
It looks like this issue hasn't progressed lately. There are so many issues that we just can't deal them all within a reasonable timeframe.
There are a couple of things you could help to get things rolling on this issue (this is an automated message, so expect that some of these are already in use):
Thanks again for your contributions! Even though we haven't been able to get this issue fixed, we hope you to report your findings and enhancement ideas in the future too!
Could we not cache the row count in the com.vaadin.data.provider.DataCommunicator and return it by a method in the Grid? As much as I found this is the place where DataProvider.size() is called. We could also fire an event, so "count labels" could be updated.
Most helpful comment
As a developer, I want to have two methods for (List)dataProvider:
In addition, one could have access to actual filtered item list e.g. getFilteredItems()
This would really simplify things
Thanks