I know I have to use grid.getDataProvider()
to get the ListDataProvider
(assuming I sent a List
to grid.setItems()
). In other to calculate the footer total I do:
Collection myItems = ((ListDataProvider)grid.getDataProvider()).getItems();
for(MyItem myItem : myItems)
total += myItem.getValue();
footer.getCell(footerCell).setText(format(total));
But this fails if I add a footer since it calculates over all items in my grid. So for example if I add:
((ListDataProvider)grid.getDataProvider()).addFilter(myFilter);
The code at the top fails since the footer isn't the filtered total but the full grid total.
That being said someone suggested I use:
grid.getDataCommunicator().fetchItemsWithRange(...);
However this is a protected method. Assuming I create my own subclass I don't even understand how that method works.
But even then that seems overly complex and something that should be simple, especially if there's an ability to add filtering in grids.
Therefore my big question is how do I calculate the footer total in a Vaadin 8 Grid if I filter the Grid?