我在每列中创建了一个带有复选框单元格的单元格表。但是当我点击任何单元格时,所有复选框都会被选中。我的实际要求是我想在行i中的复选框单元格中创建子父关系。即第一列将具有复选框,第二列将具有其多个子复选框,第三列将具有来自第二列的每个复选框的子项。我想在父选择中选择所有子项,如果任何子项未被选中,则也应该取消选择。只有选中了所有子项后,才会保留父项。
请给我一个解决方案。提前谢谢。
代码如下
final SelectionModel<ContactInfo> selectionModel = new MultiSelectionModel<ContactInfo>();
cellTable.setSelectionModel(selectionModel,
DefaultSelectionEventManager.<ContactInfo> createCheckboxManager(0));
Column<ContactInfo, Boolean> checkColumn = new Column<ContactInfo, Boolean>(new NamedCheckBoxCell(true, false)) {
@Override
public Boolean getValue(ContactInfo object) {
NamedCheckBoxCell namedCell = (NamedCheckBoxCell)this.getCell();
namedCell.setTextValue(object.getFirstName());
return selectionModel.isSelected(object);
}
};
cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("First Name"));
cellTable.setColumnWidth(checkColumn, 20, Unit.PCT);
cellTable.addCellPreviewHandler(DefaultSelectionEventManager.<ContactInfo> createCheckboxManager(1));
Column<ContactInfo, Boolean> firstNameColumn = new Column<ContactInfo, Boolean>(
new NamedCheckBoxCell(true, false)) {
@Override
public Boolean getValue(ContactInfo object) {
NamedCheckBoxCell namedCell = (NamedCheckBoxCell)this.getCell();
namedCell.setTextValue(object.getLastName());
// Get the value from the selection model.
return selectionModel.isSelected(object);
}
};
cellTable.addColumn(firstNameColumn, "Last Name");
cellTable.setColumnWidth(firstNameColumn, 20, Unit.PCT);
cellTable.addCellPreviewHandler(DefaultSelectionEventManager.<ContactInfo> createCheckboxManager(2));
// Last name.
Column<ContactInfo, Boolean> lastNameColumn = new Column<ContactInfo, Boolean>(
new NamedCheckBoxCell(true, false)) {
@Override
public Boolean getValue(ContactInfo object) {
NamedCheckBoxCell namedCell = (NamedCheckBoxCell)this.getCell();
namedCell.setTextValue(object.getAddress());
return selectionModel.isSelected(object);
}
};
lastNameColumn.setSortable(true);
cellTable.addColumn(lastNameColumn, "Address");
cellTable.setColumnWidth(lastNameColumn, 20, Unit.PCT);