I have a GWT 2.4 DataGrid associated with a SingleSelectionModel. One of the columns in the grid is a CheckboxCell, but it is not used for selection, but to set a boolean field value for the underlying item type of the row. My problem is that when I click on the checkbox, the row is selected first, then I have to click a second time to set/unset the checkbox. I would prefer that clicking outside of the checkbox does row selection, while clicking inside of the checkbox only sets/unsets the checkbox. Can anyone point me in the right direction on how to do this. I keep coming back to onBrowserEvent, but I'm not sure what to try.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There's a couple of approaches you can do, depending on what exactly you want to do it. Here are the two ideas that come to mind:
- Use a DefaultSelectionEventManager.CheckboxEventTranslator to blacklist the column
- Intercept it on a cell by cell basis with CellPreviewEvent.Handler and handle it on the DOM level by checking the EventTarget (
"click".equals(event.getType())
) and then useevent.stopPropogation()
when the EventTarget is of an input type "checkbox"
回答2:
This code solved in my case a problemn very similar to yours.
Column<SomeBean, Boolean> checkboxColumn= new Column<SomeBean, Boolean>(new CheckboxCell(true,false)) { @Override public Boolean getValue(SomeBean object) { if(object == null || object.getId() == null) return null; return selectionModel.isSelected(object); } };