使用GWT CellTableBuilder按需构建自定义行 [英] Building a custom row on demand with GWT CellTableBuilder
问题描述
因此,我的目标是创建包含小部件的额外行,提供有关表中点击行的详细信息。
我找到了适合此问题的解决方案。以下是代码示例:
public class CustomCellTableBuilder扩展了AbstractCellTableBuilder< Object> {
// here go字段,ctor等等
//我们将要显示的细节的元素ID
private设置元素;
@Override
protected void buildRowImpl(Object rowValue,int absRowIndex){
//构建主行逻辑
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();
//更新小部件的状态和外观取决于rowValue
$ b div.html(SafeHtmlUtils.fromTrustedString(widget.getElement()。getInnerHTML()));
div.end();
td.endTD();
row.endTR();
}}
值得一提的是,当你处理一些导致外观的事件时额外的行,你应该在附加到TableBuilder的CellTable上调用redrawRaw(rowIndex)。在此调用之前,需要将目标行ID添加到元素Set。
希望这有帮助。
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.
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.
这篇关于使用GWT CellTableBuilder按需构建自定义行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!