DataGrid and EditTextCell in sub rows problem

395 views
Skip to first unread message

Michael Vogt

unread,
Dec 5, 2012, 5:27:52 PM12/5/12
to google-we...@googlegroups.com
Hello.

I have EditTextCells in sub rows of a DataGrid, basically created like in the sample DataGrid. I just replace the TextCells in the sub rows with EditTextCells.

There are two problems:
- When entering edit mode in a sub row cell, the text that is shown is taken from the root row cell
- When the value ist stored, it is also stored in the root row cell

Am I doing something wrong, or is this not possible?

You can see the effect here:


Any help welcome,
Michael

Nicolas Morel

unread,
Dec 9, 2012, 4:52:30 PM12/9/12
to google-we...@googlegroups.com
And just after I wrote that, I found a way to do it without modify AbstractCellTableBuilder.

The key here is to create a HasCell for each sub row containing the sub row value or an index to find it from the main row value. I made some helper classes for this like ChildCellColumn.
MyDefaultCellTableBuilder is just a copy of the DefaultCellTableBuilder with a protected scope on style.

The custom builder is SubrowTableBuilder.

Le dimanche 9 décembre 2012 12:59:36 UTC+1, Nicolas Morel a écrit :
Hello, 

This is because the renderCell in AbstractCellTableBuilder is giving the same cellId to your root row cell and sub row cell.

I had to do this for a project so I extracted what I did and put it in a sample here : https://github.com/nmorel/gwt-celltable-subrows
I couldn't find a better solution than copy AbstractCellTableBuilder to add a new method renderChildCell. 

Michael Vogt

unread,
Dec 10, 2012, 1:53:31 PM12/10/12
to google-we...@googlegroups.com
Hello Nicolas. 

Thank you for your answer. Very helpful.

I came up with a slightly different solution (for now). I created a subclass of a column, and overrode the onBrowserEvent() call. There I receive the context with the subIndex, which is 0 when the root cell was edited, and reflects the sub row index when a cell in a sub row was edited. Then I just provide this to the fieldUpdater and the onBrowserEvent of the Cell. 

This also only allows for one level of sub rows, but I need more. This is where your approach looks more useful.


    @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);
    }


Cheers,
Michael
Reply all
Reply to author
Forward
0 new messages