使用GWT CellTableBuilder按需构建自定义行 [英] Building a custom row on demand with GWT CellTableBuilder

查看:86
本文介绍了使用GWT CellTableBuilder按需构建自定义行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GWT 2.5 RC中引入了CellTableBuilder API,但尚未提供全面的文档。是否有任何使用CellTableBuilder实现按需定制行构建的教程?示例?到目前为止我发现的唯一例子就是这一个 http://showcase2.jlabanca-testing.appspot.com/ #!CwCustomDataGrid ,但它对我来说很困惑。

因此,我的目标是创建包含小部件的额外行,提供有关表中点击行的详细信息。

解决方案

我找到了适合此问题的解决方案。以下是代码示例:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆