GWT:how to get the value of a checkbox of a cellTable

这一生的挚爱 提交于 2019-12-25 00:27:21

问题


I have this situation , i want to delete the objects in this celltable whose checkbox is Check on the clik of this "Delete" Button ,

Any idea how to get those objects whose checkbox is checked in this cellTable, when i click the delte button ..

Thanks


回答1:


If your requirement with delete single row, then You can use SingleSelectionModel otherwise MulitiSelectionModel in celltable. I have written some code with single selection model,It may give some idea. i.e.

selectionModel = new SingleSelectionModel<T>();
cellTable.setSelectionModel(selectionModel) //Set into your cellTable:

When you select a checkbox, then row will auto selected and object will set in to selection model.

  CheckboxCell checkboxCell=new CheckboxCell(true, false); 
            Column<T, Boolean> boolColumn=new Column<T, Boolean>(
                        checkboxCell) {
            @Override
            public Boolean getValue(T object) {                            
             return selectionModel.isSelected(object); 
        }
        };

On delete button click,use selected object,It will provide you a object for delete. selectionModel.getSelectedObject();




回答2:


@junaidp, As you haven't provided any code, I'm assuming that you have used CheckBoxCell to generate checkbox column and assigned MultiSelectionModel to your cellTable. You can use the following code:

Set<T> selectedObjects = ((MultiSelectionModel<T>)(cellTable.getSelectionModel())).getSelectedSet(); 

Here selectedObjects will be of type T, that you should have specified as CellTable<T>. selectedObjects will be objects, associated to checked rows only.




回答3:


You can check for a given cell's selected status with:

Column<CellInfo, Boolean> checkColumn =
      new Column<MemberInfo, Boolean>(new CheckboxCell(true, false)) {
        public Boolean getValue(CellInfo object) {
          // Get the value from the selection model.
          return selectionModel.isSelected(object);
        }
      };


来源:https://stackoverflow.com/questions/12476521/gwthow-to-get-the-value-of-a-checkbox-of-a-celltable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!