Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a custom row on demand with GWT CellTableBuilder

Tags:

gwt

In GWT 2.5 RC CellTableBuilder API was introduced but there are no comprehensive documentation available yet. Is there any tutorial\example of implementing on-demand custom row building with CellTableBuilder? The only example I've found so far was this one http://showcase2.jlabanca-testing.appspot.com/#!CwCustomDataGrid but it is quite confusing for me.

So, my goal is to create extra row containing widget that provides details about clicked row in a table.

like image 322
Anton Kirillov Avatar asked Jul 03 '12 07:07

Anton Kirillov


1 Answers

I've found suitable solution for this problem. Here is the code sample:

public class CustomCellTableBuilder extends AbstractCellTableBuilder<Object>{
//here go fields, ctor etc.

//ids of elements which details we are going to show 
private Set elements;

@Override
protected void buildRowImpl(Object rowValue, int absRowIndex){
   //building main rows logic 

    if(elements.contains(absRowIndex)){
        buildExtraRow(absRowIndex, rowValue);
        elements.add(absRowIndex);
    }
}

private void buildExtraRow(int index, Object rowValue){
    TableRowBuilder row = startRow();
    TableCellBuilder td = row.startTD().colSpan(getColumns().size());
    DivBuilder div = td.startDiv();

    Widget widget = new Widget();

    //update widget state and appearance here depending on rowValue

    div.html(SafeHtmlUtils.fromTrustedString(widget.getElement().getInnerHTML()));

    div.end();
    td.endTD();
    row.endTR();
}}

It should be mentioned, that when you handle some event which leads to appearance of extra row, you should invoke redrawRaw(rowIndex) on CellTable which is attached to TableBuilder. And before this call it is necessary to add target row ID to elements Set.

Hope this was helpful.

like image 178
Anton Kirillov Avatar answered Oct 19 '22 22:10

Anton Kirillov