简体   繁体   English

GWT + DataGrid冻结/解冻行选择

[英]GWT+DataGrid freeze/unfreeze row selection

So I have implemented a SingleSelectionModel to select only single row in the DataGrid. 因此,我实现了SingleSelectionModel以仅选择DataGrid中的单行。

final SingleSelectionModel<Entity> selectionModel = new SingleSelectionModel<>(keyProvider);

And I've created a checkbox that should freeze/unfreeze row selection. 而且我创建了一个复选框,该复选框应冻结/取消冻结行选择。 In other words, when the checkbox is checked, current row must be selected (blue highlighted cuz I'm using the SingleSelectionModel), and user should not be able to select another row via keyboard/mice while checkbox is checked. 换句话说,当选中该复选框时,必须选中当前行(蓝色突出显示的cuz,因为我正在使用SingleSelectionModel),并且在选中该复选框时,用户不能通过键盘/鼠标选择另一行。 The row still must stay selected. 该行仍必须保持选中状态。

// disable row selection using selection model
    disableSelection.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            // do stuff, any suggestions guys?
        }
    });

Maybe using NoSelectionModel, or adding a selectionChangeHandler to the existing selection model. 可能使用NoSelectionModel,或将selectionChangeHandler添加到现有选择模型中。 Thanks. 谢谢。

You can try: 你可以试试:

NoSelectionModel<Entity> noSelectionModel = new NoSelectionModel<Entity();
...
disableSelection.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
    @Override
    public void onValueChange(ValueChangeEvent<Boolean> event) {
        myDataGrid.setSelectionModel(event.getValue() ? noSelectionModel : selectionModel);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM