GWT CellTable - set column width

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

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

相关标签:
4条回答
  • 2021-01-04 02:33

    You could use a stylename for the specific column, using the addColumnStyleName(int index, java.lang.String styleName) method.

    Javadoc for CellTable

    0 讨论(0)
  • 2021-01-04 02:45

    The GWT documentation for CellTable covers this, see: http://www.gwtproject.org/doc/latest/DevGuideUiCellTable.html

    Under "Controlling Column Widths".

    0 讨论(0)
  • 2021-01-04 02:50

    What worked for me is adding a new class in my css. This class gets applied only to select elements whose length varies depending on data.

    .__gwt_cell select{
        width:170px;
    }
    

    Then applying it on my particular cell style like o:

    table.getColumn(3).setCellStyleNames("yourstyle");
    
    0 讨论(0)
  • 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<Integer> widths)
    {
        TableElement tel = TableElement.as(getElement());
        NodeList<Element> colgroups = tel.getElementsByTagName("colgroup");
        if (colgroups.getLength() == 1)
        {
           TableColElement cge = TableColElement.as(colgroups.getItem(0));
           NodeList<Element> 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");
    
           }
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题