开发者

How to set entire column's background color in CellTable GWT

I want to find a way to set an entire column's background color in CellTable in GWT, but no luck. In CellTable's style, I only found the style cellTableLastColumn and cellTableFirstColumn which could be used to set the background color for the last and first column (Those two work fine). Does any body know how to set the entire column background color for any column by passing the column index as the parameter? Thank you very开发者_JAVA技巧 much.


You can use table.addColumnStyleName(colIndex, "mystyle") to tell CellTable to add mystyle to the table's <colgroup>. This results in HTML like

<table ...>
  <colgroup><col><col><col class="mystyle"><col>...</colgroup>
  ...

With a CSS rule like mystyle { background-color : #D0E4F6; }, this sets the background color of the whole column, including the header.

Unfortunately, this is not enough because the GWT CSS rules for even/odd rows will have priority and style all <td>'s of your column (except the header), overwriting your background color.

To fix this, use column.setCellStyleNames("mystyle") on the column. This causes the <td>'s of the column to receive the class mystyle. You can then use CSS like

.mystyle, td.mystyle {
  background-color : #D0E4F6;
}

to set the background color of the column (header) and the <td>'s.


You can use addColumnStyleName to add a CSS class name to a column, just like you use addStyleName on a Widget.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜