Podjąłem inne podejście, aby rozwiązać ten sam problem.
Podstawową koncepcją jest użycie elementów domowych do dodawania i usuwania wierszy na podstawie zdarzenia. Poniższy kod jest abstrakcyjnym rozszerzeniem CellTable. Będziesz chciał wywołać tę metodę ze zdarzenia, które zostanie wyrzucone z kliknięcia, aby rozwinąć wiersz.
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 służy do śledzenia, który element jest „rozszerzony”, może to być prawdopodobnie osiągnięty za pomocą klas lub identyfikatory. W razie potrzeby mogę rozwinąć więcej na temat CellTable, wydarzeń, widoków i działań.
Dobrze wiedzieć, dziękuję! Nadal pracuję nad rozwiązaniem dla wersji 2.4 (z magią CSS + ręczną aktualizacją wysokości tabeli po rozwinięciu). – alexandroid