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

<img src="https://i.stack.imgur.com/N6Zo0.png" alt="enter image description here">

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

Answer1:

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();

Answer2:

@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 <strong>selectedObjects</strong> will be of type T, that you should have specified as CellTable<T>. <strong>selectedObjects</strong> will be objects, associated to checked rows only.

Answer3:

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); } };

人吐槽 人点赞

Recommend

Comment

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:GWT:how to get the value of a checkbox of a cellTable