当 SelectionMode 为 MULTI 时,隐藏 Flow 组件网格中的“全选”复选框 (Vaadin 21)

Chr*_*ris 2 vaadin vaadin-grid vaadin-flow vaadin21

当您在 Vaadin v21 中创建网格组件并切换到多选模式时,顶部会有一个“全选”复选框。如何禁用它?网格的默认行为似乎不同,因此 Vaadin 版本之间的解决方案也不同。

Grid<Person> grid = new Grid<>(Person.class, false);
grid.setSelectionMode(Grid.SelectionMode.MULTI);
grid.setItems(personRepository.findAll());

Run Code Online (Sandbox Code Playgroud)

Chr*_*ris 5

您必须从网格中获取 SelectionModel,才能启用或禁用“全选”复选框:

Grid<Person> grid = new Grid<>(Person.class, false);
grid.setSelectionMode(Grid.SelectionMode.MULTI);
((GridMultiSelectionModel<?>) grid.getSelectionModel())
      .setSelectAllCheckboxVisibility(
            GridMultiSelectionModel.SelectAllCheckboxVisibility.HIDDEN
      );
grid.setItems(personRepository.findAll());
Run Code Online (Sandbox Code Playgroud)