GWT CellTable with checkbox selection and on row click event

喜你入骨 提交于 2019-12-04 09:20:46

问题


How to call a method when some row is clicked using the checkbox selection model?

I'm setting the checkbox selection model like this:

table.setSelectionModel(selectionModel, 
      DefaultSelectionEventManager.<T> createCheckboxManager(0));

回答1:


I found a solution! Instead of using createCheckboxManager(), use createCustomManager() passing by argument an EventTranslator that extends the CheckboxEventTranslator and do a delegation of the translateSelectionEvent method, intercepting only the events ignored by the super (CheckboxEventTranslator).

The source code:

table.setSelectionModel(selectionModel, 
    DefaultSelectionEventManager.createCustomManager(
        new DefaultSelectionEventManager.CheckboxEventTranslator<T>() {
            @Override
            public SelectAction translateSelectionEvent(CellPreviewEvent<T> event) {
                SelectAction action = super.translateSelectionEvent(event);
                if (action.equals(SelectAction.IGNORE)) {
                    GWT.log("DO WHAT YOU WANT!!!");
                    return SelectAction.IGNORE;
                }
                return action;
            }
        }
    )
);



回答2:


Create a function that you call,

table.setSelectionModel(selectionModel, ClassName.myMethod(0));

static <T> DefaultSelectionEventManager<T> myMethod(int column) {
   //call whatever functions you want
   return DefaultSelectionEventManager.<T> createCheckboxManager(column);
}


来源:https://stackoverflow.com/questions/5637598/gwt-celltable-with-checkbox-selection-and-on-row-click-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!