I have a grid that is loaded from a list using the ListDataProvider.
The grid is in multi select mode.
When I use the selection model to delete selected models I call refreshAll on the ListDataProvider.
The problem is that the selection model doesn’t appear to be updated when I call refreshAll and as a result still contains the (now deleted) rows.
To fix the problem I had to manually update the selection model which seems wrong.
To wit:
private Grid<ActivityLine> grid;
private ListDataProvider<ActivityLine> activityProvider;
private List<ActivityLine> activityLines;
grid = new Grid<>();
grid.setSelectionMode(Grid.SelectionMode.MULTI);
activityLines = activities.parallelStream().sorted().map(t -> new ActivityLine(t))
.collect(Collectors.toList());
activityProvider = new ListDataProvider<>(activityLines);
this.grid.setDataProvider(activityProvider);
// delete handler
private void deleteActivities()
{
MultiSelect<ActivityLine> selections = this.grid.asMultiSelect();
selections.getValue().parallelStream().forEach(line -> {
new ActivityDao().delete(line.getActivity());
this.activityLines.remove(line);
// I wasn't expecting to need this line.
selections.updateSelection(new HashSet<ActivityLine>(), Stream.of(line).collect(Collectors.toSet()));
});
this.activityProvider.refreshAll();
}