我试图搜索您的要求是否可以通过某些 API 功能来满足,但找不到。
所以我以编程方式实现了这种行为。请尝试以下代码:
grid.addRecordClickHandler(new RecordClickHandler() {
@Override
public void onRecordClick(RecordClickEvent event) {
ListGridRecord record = (ListGridRecord) event.getRecord();
ListGridRecord[] selectedRecords = grid.getSelectedRecords();
if (selectedRecords != null) {
List<ListGridRecord> selectedRecordsList = Arrays.asList(selectedRecords);
if (selectedRecordsList.contains(record)) {
// the record is already selected, so deselect it.
grid.deselectRecord(record);
} else {
// the record is already deselected, so select it.
grid.selectRecord(record);
}
} else {
// the record is already deselected, so select it.
grid.selectRecord(record);
}
}
});
这里grid是ListGrid
.