Append custom style to a GWT CellTable (in this case all cells)

南楼画角 提交于 2019-11-27 01:51:48

问题


I have a case where I want to append

white-space: nowrap;

to the style of each cell in my CellTable. Currently it applies to all tables, but it would be nice to know both have to apply it for a specific CellTable, and all CellTables.


回答1:


CellTables have their own CssResource. To override this style applied to all cells in a cellTable, create a new css file :

/* Incremental changes from CellTable.css */ 
.cellTableCell {
  white-space: nowrap;
}

Then create your own CellTable.Resources interface :

public interface TableResources extends CellTable.Resources {

    /**
       * The styles applied to the table.
       */
    interface TableStyle extends CellTable.Style {
    }

    @Override
    @Source({ CellTable.Style.DEFAULT_CSS, "MyOwnCellTableStyleSheet.css" })
    TableStyle cellTableStyle();

}

Finally, when creating your cellTable, use the constructor that lets you specify which Resources to use

CellTable<Object> myCellTable = new CellTable<Object>(15, GWT.create(TableResources.class));

For a working example, look at the Expenses sample provided in the GWT SDK.




回答2:


Or you could do this the easy way:

CellTable<YourObj> yourTable = new CellTable<YourObj>();
yourTable.getElement().getStyle().setWhiteSpace(WhiteSpace.NOWRAP);

No css files, no weird boilerplate code.



来源:https://stackoverflow.com/questions/6386070/append-custom-style-to-a-gwt-celltable-in-this-case-all-cells

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