Vaadin-Grid:全选复选框在 UI 中不起作用

问题描述

问题:

我有一个延迟加载的网格,因此我的数据不在内存中。

显示复选框以选择/取消选择我使用的所有 this Question。 我的代码如下所示:

Grid<CustomClass> grid;
...
// set selection mode
grid.setSelectionMode(SelectionMode.MULTI);
// make select all check Box visible
GridSelectionModel<CustomClass> selectionModel = grid.getSelectionModel();
((GridMultiSelectionModel<CustomClass>) selectionModel)
    .setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility.VISIBLE);

问题是,如您所见,该复选框在 UI 中不起作用:

enter image description here

如果我使用以下代码记录所选项目,则复选框按预期工作

grid.addSelectionListener(l -> {
    log.info("selected: " + l.getAllSelectedItems().size());
});

问题:

如何才能使复选框在 UI 中也能正常工作?

解决方法

我发现在 UI 中更新复选框的解决方案是在侦听器中添加 dataPovider.refreshAll()

解决方案代码:

grid.addSelectionListener(l -> {
    ...
     dataPovider.refreshAll();
    ...
});