GWT 2.5 DataGrid SelectionModel with Subrows

773 views Asked by At

When using TableBuilder to create rows and sub rows, selection model isn't working as expected. When clicking on a subrow's checkbox the row isn't been selected, however, the parent row become selected instead.

I tried to overload onBrowserEvent of the CheckboxCell in order to manually handle the selection but it seems that the DataGrid itself fires the selection event when pressing the checkboxcell.

In case where rows and subrows are from the same type, how can I add selection model that supports both rows and subrows?

1

There are 1 answers

0
Ankit Singla On
@Override
public void onBrowserEvent(Context context, Element elem, final T object,
        NativeEvent event) {
    // The provided row is always the root row, so we need to find the
    // correct one when a sub row was edited
    actualIndex = context.getSubIndex();
    actualObject = object;
    if (0 != context.getSubIndex() && object instanceof RowDTO) {
        actualIndex = context.getSubIndex();
        actualObject = (T) ((RowDTO) object).getChild(actualIndex - 1);
        context = new Context(context.getIndex(), context.getColumn(),
                actualObject, actualIndex);
    }

    ValueUpdater<C> valueUpdater = (getFieldUpdater() == null) ? null
            : new ValueUpdater<C>() {
                @Override
                public void update(C value) {
                    getFieldUpdater().update(actualIndex, object, value);
                }
            };

    getCell().onBrowserEvent(context, elem, getValue(actualObject), event,
            valueUpdater);
}