6

I'm trying to use the new GWT CellTable widget but my table needs to support one row expansion, i.e. there is a zippy on the left of a row and when it's clicked, the row should expand to provide more detail information and this row should span across all columns. Is it possible to achieve this with the CellTable? How do I add a row that spans all columns between other rows dynamically?

Any help will be appreciated!

smallbec
  • 429
  • 5
  • 10

4 Answers4

2

GWT 2.5 will add a CellTableBuilder with the exact goal of allowing this kind of things.

You can find a live example at http://showcase2.jlabanca-testing.appspot.com/#!CwCustomDataGrid (click on the "show friends" cells)

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Good to know, thank you! I am still working on a solution for 2.4 (with CSS magic + manually updating table height upon expansion). – alexandroid Oct 27 '11 at 10:29
0

Can you not make the additional row invisible using getRowElement(int row) and using DOM methods to set display 'none' when rendered and as blank when the button, to show it, is hit.

Gaurav Saxena
  • 4,257
  • 3
  • 19
  • 17
0

I am working on the solution too and my plan for now is to use CSS classes + manual styles manipulation to make it look as I need. Not sure if I be able to merry it with GWT though: http://jsfiddle.net/7WFcF/

alexandroid
  • 1,469
  • 2
  • 15
  • 32
  • @ThomasBroyer (I cannot comment directly on his answer for some reason) - example from GWT 2.5 still uses columns and it is not clear if it would allow to make a cell which spans across all columns... – alexandroid Oct 25 '11 at 02:46
0

I took a different approach to solve this same problem.

The basic concept is using dom elements to add and remove rows based on an event. The following code is an abstract extension of CellTable. You'll want to call this method from your event that gets fired from the click to expand a row.

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NodeList;

public abstract class ActionCellTable<T> extends CellTable<T> {
    protected abstract void addActionsColumn();

Integer previousSelectedRow = null;

public void displayRowDetail(int selectedRow, Element e){
    //Get the tbody of the Cell Table
    //Assumption that we want the first (only?) tbody.
    Element tbody = this.getElement().getElementsByTagName("tbody").getItem(0);
    //Get all the trs in the body
    NodeList<Element> trs = tbody.getElementsByTagName("tr");

    //remove previously selected view, if there was one
    if(previousSelectedRow!=null){
        trs.getItem(previousSelectedRow+1).removeFromParent();
        //If the current is further down the list then the current your index will be one off.
        if(selectedRow>previousSelectedRow)selectedRow--;
    }
    if(previousSelectedRow==null || selectedRow != previousSelectedRow){// if the are equal we don't want to do anything else
        Element td = Document.get().createTDElement();
        td.setAttribute("colspan", Integer.toString(trs.getItem(selectedRow).getChildNodes().getLength()));
        td.appendChild(e);

        Element tr = Document.get().createTRElement();
        tr.appendChild(td);
        tbody.insertAfter(tr, trs.getItem(selectedRow));
        previousSelectedRow=selectedRow;
    } else {
        previousSelectedRow=null;
    }
}

}

previousSelectedRow is used to track which item is "expanded", this could probably be achieved using classes or IDs. If needed I can elaborate more on the CellTable, events, views, and activities.

drye
  • 1,362
  • 2
  • 15
  • 25
  • I will be the first to admit that this may be a hacky solution, but with the level(read lack) of control that you have with CellTables, it was the best I came up with. The 2.5 solution looks great, but until it's released it's of little help to me now. The Builder concept that they introduce will make these sort of customization a lot less hacky. – drye Jan 16 '12 at 21:25