GWT CellTable - set column width

前端 未结 4 2050
臣服心动
臣服心动 2021-01-04 02:03

Is it possible to set the column width of CellTable in GWT?

4条回答
  •  没有蜡笔的小新
    2021-01-04 02:56

    EDIT: As of GWT 2.2 table.setWidth and table.setColumnWidth are supported

    table.setWidth("100%", true);
    table.setColumnWidth(nameColumn, 35.0, Unit.PCT);
    table.setColumnWidth(addressColumn, 65.0, Unit.PCT);
    

    I was able to extend the CellTable with a method that sets the widths programmatically. It's a bit of a hack since all the real methods that should do this are private to CellTable and it seems like GWT should provide this method directly, but it seems to work.

    public void setColumnWidths(List widths)
    {
        TableElement tel = TableElement.as(getElement());
        NodeList colgroups = tel.getElementsByTagName("colgroup");
        if (colgroups.getLength() == 1)
        {
           TableColElement cge = TableColElement.as(colgroups.getItem(0));
           NodeList cols = cge.getElementsByTagName("col");
           for (int j = 0; j < widths.size(); j++)
           {
               TableColElement column = null;
               if (cols.getLength() > j)
               {
                   column = TableColElement.as(cols.getItem(j));
               }
               else
               {
                   column = cge.appendChild(Document.get().createColElement());
               }
    
               column.setWidth(widths.get(j)+"px");
    
           }
    
        }
    }
    

提交回复
热议问题