是否有“全选"?Vaadin 13 Grid 中的 checkbok(即使在过滤条件下也能工作,甚至当某些数据不在缓存中时?) [英] is there a "Select All" checkbok in Vaadin 13 Grid (that works even with filter conditions & when even some of the data is NOT in the cache?)

查看:26
本文介绍了是否有“全选"?Vaadin 13 Grid 中的 checkbok(即使在过滤条件下也能工作,甚至当某些数据不在缓存中时?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Vaadin 13 中,我为我的网格启用了多选",效果很好.然而,通常,即使经过过滤,我也有数百个项目(因此选择每个项目会很乏味).在我多年前使用的旧 gwt网格"工具中,他们有一个复选框,该复选框将出现在顶行/标题级别,如果选中,将对表中的所有行执行全选/取消全选(之后过滤).Vaadin 13 中是否存在这样的解决方案?如果没有,是否有任何(简单且安全的)解决方法来实现类似的目标?(注意:这可能比看起来要复杂一些,因为全选/取消全选复选框应该选择所有项目甚至,如果它们没有被显示或者甚至在后端缓存中....它应该根据过滤条件选择所有记录....)

解决方案

Grid 默认不显示全选";当您使用内存中没有所有项目的数据提供程序时,请选中复选框.这样做的原因是它有可能给大型数据库带来很多麻烦.您仍然可以通过执行以下操作来显式启用它:

<预><代码>导入 com.vaadin.flow.component.grid.Grid;导入 com.vaadin.flow.component.grid.Grid.SelectionMode;导入 com.vaadin.flow.component.grid.GridMultiSelectionModel;导入 com.vaadin.flow.component.grid.GridMultiSelectionModel.SelectAllCheckboxVisibility;((GridMultiSelectionModel) grid.getSelectionModel()).setSelectAllCheckboxVisibility(SelectAllCheckboxVisibility.VISIBLE);

参见 https://github.com/vaadin/vaadin-grid-flow/issues/549 了解更多详情.

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....)

解决方案

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.

这篇关于是否有“全选"?Vaadin 13 Grid 中的 checkbok(即使在过滤条件下也能工作,甚至当某些数据不在缓存中时?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆