Adding new row to a listgrid which is grouped in gwt

866 Views Asked by At

My smart gwt listgrid is grouped by one of its columns. If I want to add a new row to the a group in the grid, I click on the group and the add button. A row is added as the last row of the grid for editing irrespective of the grouping. Once the row is saved, its shown in the correct group. Is there a way to add the new row for editing in the same group itself instead as the last row?

1

There are 1 best solutions below

0
On

If you would like to use pending edits, you have to use a TreeGrid instead of a ListGrid. With the underlying Tree you can add new Records to a dedicated TreeNode by calling:

tree.add(node, parent);

To get the similar look and feel of a grouped ListGrid you nedd to customize the TreeGrid a little bit:

setShowOpenIcons(false);
setShowDropIcons(false);
setFolderIcon(null);
setNodeIcon(null);

By overriding the method:

@Override
protected String getCellStyle(ListGridRecord record, int rowNum, int colNum) {
    if (data.isFolder((TreeNode) record)) {
        return "myOwnHeader";
    }
    return super.getCellStyle(record, rowNum, colNum);
}

you can define a custom style for all headers like this:

.myOwnHeader{
    border-bottom: 1px solid #8299B8;
    color: #3764A3;
    font-family: Tahoma,Verdana,sans-serif;
    font-weight: bold;
}