GWT CellTable - set column width

╄→гoц情女王★ 提交于 2019-12-30 05:44:04

问题


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


回答1:


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");

       }

    }
}



回答2:


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

Javadoc for CellTable




回答3:


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");



回答4:


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

Under "Controlling Column Widths".



来源:https://stackoverflow.com/questions/4461749/gwt-celltable-set-column-width

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!