题
我试图使用新的GWT CellTable组件,但是我的表需要支持一个行扩展,也就是说,左边一排,并单击时,该行应扩大到提供更详细的信息和活泼此行应该在所有的列跨越。是否有可能与CellTable实现这一目标?如何添加一排动态?
其他行之间的跨度中的所有列任何帮助将理解!
解决方案
2.5 GWT将添加一个CellTableBuilder
具有允许这样的东西的确切目标。
您可以在这里找到 HTTP直播例如://showcase2.jlabanca-testing.appspot .COM /#!CwCustomDataGrid (点击 “查看朋友” 细胞)
其他提示
你能不能使附加行无形使用getRowElement(int row)
并使用DOM方法来设置显示在呈现时和空白的按钮,以显示它是打“无”。
我工作的解决方案也和我现在的计划是使用CSS类+手动操作风格,使它看起来像我所需要的。不知道如果我能与GWT虽然花落它: http://jsfiddle.net/7WFcF/
我采取了不同的方法来解决这个相同的问题。
的基本概念是使用DOM元素来添加和删除基于事件行。以下代码是CellTable的抽象扩展。你会想打电话给您的事件,但未通过点击射击,扩大行此方法。
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用于跟踪哪个项目是“扩展”,这也许可以使用类或ID来实现。如果需要,我可以更多地讨论了CellTable,事件,观点和活动。
不隶属于 StackOverflow