Frage

I need a 'custom selection model' for GWT CellTable. One of the columns in CellTable is a Checkbox column.

Basic rquirements (both work in solution below):
- Row click (not on checkbox), selects that row and un-selects all other rows.
- Checkbox selection should select/un-select that row only.

Following is the code I am using, but its very very slow. Any guidance would be appreciated.

final SelectionModel<T> selectionModel = new MultiSelectionModel<T>();
dataTable.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)) {
                            selectionModel.clear();
                            return SelectAction.TOGGLE;
                        }
                        return action;
                    }
                }
            )
        );

Following is the code snipped for CheckColumn callback.

Column<T, Boolean> checkColumn = new Column<T, Boolean>(
    new CheckboxCell(true, false))
        {
            @Override
            public Boolean getValue(T t)
            {
                // Get the value from the selection model.
                return selectionModel.isSelected(t);
            }
        };
War es hilfreich?

Lösung

I have put in a KeyProvider for the CellTable and its not slow anymore. :)

ProvidesKey<T> keyProvider = new ProvidesKey<T>() {
    public Object getKey(T t) {
        return tip == null? null : tip.getId();
    }
};
dataTable = new CellTable<T>(PAGE_SIZE, keyProvider);

Andere Tipps

You could just whitelist your checkbox

int checkboxColumn = 0;
DefaultSelectionEventManager.createCustomManager(new DefaultSelectionEventManager
                                      .WhitelistEventTranslator(checkboxColumn));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top