In Vaadin 13, I have enabled "multiselect" for my grids, which works great. However, often, even after filtering, I have hundreds of items (so selecting each of them would be tedious). In an old old gwt "grid" tool I used years ago, they had a checkbox that would appear on the top row/header level that, if selected, would do a select all/unselect all for all the rows in the table (after filtering). Does such a solution exist in Vaadin 13? If not, any (easy and safe) workaround to achieve something similar? (Note: It may be a little trickier to do than it first seems, since the select all/unselect all checkbox should select all items even if they're not being displayed or even in the back-endcache....it should select all records based on the filter condition....)
Asked
Active
Viewed 1,359 times
3
-
I don't get what you mean by "It may be a little trickier to do than it first seems, since the select all/unselect all checkbox should select all items even if they're not being displayed" while you also say "it should select all records based on the filter condition". Items that are not displayed aren't displayed due to the fact, that the filter condition filters them, are they? So why should items that are not displayed be selected? Or are you refering to pagination or something like that? – codinghaus Mar 20 '19 at 14:24
-
@codinghaus I'm referring to the fact that I'm usinng "Lazy Loading" as described here: "Lazy Loading Data from a Backend Service" section on this link: https://vaadin.com/docs/flow/binding-data/tutorial-flow-data-provider.html – Jonathan Sylvester Mar 20 '19 at 22:24
1 Answers
7
Grid does by default not show a "Select all" checkbox when you're using a data provider that doesn't have all items in memory. The reason for this is that it has the potential of causing lots of trouble with a big database. You can still explicitly enable it by doing something like this:
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.Grid.SelectionMode;
import com.vaadin.flow.component.grid.GridMultiSelectionModel;
import com.vaadin.flow.component.grid.GridMultiSelectionModel.SelectAllCheckboxVisibility;
((GridMultiSelectionModel<?>) grid.getSelectionModel())
.setSelectAllCheckboxVisibility(SelectAllCheckboxVisibility.VISIBLE);
See https://github.com/vaadin/vaadin-grid-flow/issues/549 for more details.

MrMaavin
- 1,611
- 2
- 19
- 30

Leif Åstrand
- 7,820
- 13
- 19
-
I also had to add `dataPovider.refreshAll()` in the `grid.addSelectionListener()` that the items where selected in the UI. – MrMaavin Jul 20 '21 at 08:05