GWT CheckboxCell阻止在CellTable中的选择 [英] GWT CheckboxCell hinders selection in CellTable
问题描述
我发现如果您有一个GWT CellTable
并添加一个包含 CheckboxCell
的列, a SingleSelectionModel
不再工作。此单元格类型阻碍行选择。
下面的代码示例演示了在2.5.0.rc1中的此行为。
I discovered that if you have a GWT CellTable
and add a column that contains a CheckboxCell
, the selection via a SingleSelectionModel
does not work anymore. This cell type does hinder the row selection.
Following a code sample that demonstrates this behaviour in 2.5.0.rc1.
final CellTable<LicenseDto> licenseTable = new CellTable<LicenseDto>();
final SingleSelectionModel<LicenseDto> selectionModel = new SingleSelectionModel<LicenseDto>();
licenseTable.setSelectionModel(selectionModel);
//--- If I add this column, the selection does work.
Column<LicenseDto, String> workingColumn = new Column<LicenseDto, String>(new TextCell()) {
@Override
public String getValue(LicenseDto object) {
return "Works";
}
};
workingColumn.setFieldUpdater(new FieldUpdater<LicenseDto, String>() {
@Override
public void update(int index, LicenseDto object, String value) {
;
}
});
licenseTable.addColumn(workingColumn);
//--- If I add this column, the selection does NOT work anymore.
Column<LicenseDto, Boolean> notWorkingColumn = new Column<LicenseDto, Boolean>(new CheckboxCell(true, true)) {
@Override
public Boolean getValue(LicenseDto object) {
return object.getEnabled();
}
};
notWorkingColumn.setFieldUpdater(new FieldUpdater<LicenseDto, Boolean>() {
@Override
public void update(int index, LicenseDto object, Boolean value) {
presenter.enableLicense(object, value);
}
});
licenseTable.addColumn(notWorkingColumn);
initWidget(licenseTable);
您可以组合多个单元格并将它们添加到表中(例如 LinkActionCell
等)。只要没有 CheckboxCell
,用 SingleSelectionModel
的蓝色选择就像一个魅力。有没有人看到我在这个 CheckboxCell
上做错了或有错误?
You can combine multiple cells and add them to the table (e.g. LinkActionCell
etc). As long as there is no CheckboxCell
, the blue selection with the SingleSelectionModel
works like a charm. Does anyone see what I do wrong with this CheckboxCell
or is there a bug?
推荐答案
谢谢Thomas!问题是,我设置 handlesSelection = true
甚至认为我不处理任何东西。将其设置为false可以解决问题。
顺便说一句,我添加一个 fieldUpdater
到列,以处理复选框的勾选或取消勾选:
Thank you Thomas! The problem was that I set handlesSelection = true
even thought I don't handle anything. Setting it to false solves the problem.
By the way, I add a fieldUpdater
to the column to handle a tick or untick of the checkbox:
Column<LicenceDto, Boolean> enableLicenseColumn = new Column<LicenceDto, Boolean>(new CheckboxCell(false, false)) {
@Override
public Boolean getValue(LicenceDto object) {
return object.getEnabled();
}
};
enableLicenseColumn.setFieldUpdater(new FieldUpdater<LicenceDto, Boolean>() {
@Override
public void update(int index, LicenceDto object, Boolean value) {
presenter.enableLicense(object, value);
}
});
问题得到解答。
这篇关于GWT CheckboxCell阻止在CellTable中的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!