我已经拿到了表格,并且想了解有关该onClick(ClickEvent event)
方法中单击的行的一些信息。例如,如果我单击CheckBox
标题行中的 ,CheckBox
则应自动检查所有其他 es(类似于“全选”)。单击其他一些后CheckBox
,我想获得相应行的ID。我该怎么做?
解决了。
CheckBox selectCb = new CheckBox();
selectCb.addClickHandler(this);
selectCb.getElement().setId(CheckBoxIds.SELECT_ALL);
@Override
public void onClick(ClickEvent event) {
// OK, an "instanceof Widget" would intercept the if condition below
if (event.getSource() instanceof CheckBox) {
CheckBox checkBox = (CheckBox) event.getSource();
String elementId = checkBox.getElement().getId();
if (elementId.equals(CheckBoxIds.SELECT_ALL)) {
boolean checked = checkBox.getValue();
LOGGER.info("Checked: " + checked);
}
}
}
编辑#1。
ClickHandler
标题复选框,其他复选框,按钮等的各种s。
/**
* The {@link ClickHandler} for the header row
*/
private ClickHandler mHeaderCbClickHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
CheckBox checkBox = (CheckBox) event.getSource();
boolean checked = checkBox.getValue();
for (int row = NO_DATA_HEADER_ROWS_COUNT; row < mFlexTable.getRowCount(); row++) {
CheckBox dataCb = (CheckBox) mFlexTable.getWidget(row, MockDataProvider.CHECK_COLUMN_INDEX);
dataCb.setValue(checked);
}
}
};
/**
* The {@link ClickHandler} for a row with data
*/
private ClickHandler mRowCbClickHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
}
};
/**
* The {@link ClickHandler} for {@link Button}s
*/
private ClickHandler mButtonClickHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
}
};
// Use
CheckBox selectCb = new CheckBox();
selectCb.addClickHandler(mHeaderCbClickHandler);
// selectCb.getElement().setId(CheckBoxIds.SELECT_ALL); Not necessary now