本文介绍了GWT CellTable - 设置列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在GWT中设置 CellTable
的列宽?
解决方案
$ b $ pre $ table.setWidth(100% ,是);
table.setColumnWidth(nameColumn,35.0,Unit.PCT);
table.setColumnWidth(addressColumn,65.0,Unit.PCT);
我能够通过一种以编程方式设置宽度的方法来扩展CellTable。这是一个黑客,因为所有真正的方法应该做到这一点是CellTable的私有,看起来GWT应该直接提供这种方法,但似乎工作。
<$ 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);
}
}
}
Is it possible to set the column width of CellTable
in GWT?
解决方案
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");
}
}
}
这篇关于GWT CellTable - 设置列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!