1

我得到下一个代码,带有第一列的 listgrid 是一个检查:

private ListGrid listGrid = new ListGrid();
....
....
listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
    listGrid .addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            //TODO
        }
    });

单击一行时,我想在我的 listgrid 上即时选择或取消选择检查组件。

我该怎么做?

4

1 回答 1

1

我试图搜索您的要求是否可以通过某些 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);
            }
        }
});

这里gridListGrid.

于 2013-09-24T07:36:50.207 回答