how to set the row color of CellTable based on values in a column

3,008 views
Skip to first unread message

tong123123

unread,
Jun 20, 2012, 3:37:13 AM6/20/12
to google-we...@googlegroups.com
as shown in the attached diagram, there is a column with value 10, 20, 30, 40. I want to  set the row color based on this column value, for example, 10 is white, 20 is  yellow...., any method to do it?

I see there is
public void setRowStyles(RowStyles<T> rowStyles)
and
java.lang.String getStyleNames(T row, int rowIndex)

but I do not know how to use it? and the result of the getStyleNames is the css class name? but with this hide the origin style like row
in highlighted?

thanks

summaryView.png

tong123123

unread,
Jun 20, 2012, 6:36:49 AM6/20/12
to google-we...@googlegroups.com
there is some progress, I use the code as follow:
// set RowStyles
table.setRowStyles(new RowStyles<Log>(){
@Override
public String getStyleNames(Log row, int rowIndex) {
if (row.getSeverity_cd().equalsIgnoreCase("W ")){
    return "warning";
}else if (row.getSeverity_cd().equalsIgnoreCase("C ")){
    return "critical";
}else
    return null;
}
});

and the result is shown as attached.

just feel the css need use something like following:
.critical{
   background-color:red !important;
}

which seem not normal css syntax (!important).

and I do not know where is the origin rowStyle come from (at first, I want to use CellTable.getRowStyles in else part but found not this api and so return null, so lucky the origin style still preserve, that is, if the row.getSeverity_cd() equals to other character than 'W ', 'C ', the origin style can preserve, but I do not know the background machanism).

 








rowStyle3.png
Message has been deleted

tong123123

unread,
Jun 20, 2012, 11:06:12 PM6/20/12
to google-we...@googlegroups.com
the problem becomes very complicated, as the row background color depends on a column value, but when the row is selected, the font color is white, so if the background color is yellow as attaced and when the row is highlighted, the font is in white color and so difficult to see.
But the worst is the column value will change the row's background color to other value, and so the selected row font color need to be changed according to the column value also!! (if background color is yellow, font may need a darker color, when background color is grey on some column value, the font color need a lighter color...)

is this possible?

tong123123

unread,
Jun 21, 2012, 3:11:01 AM6/21/12
to google-we...@googlegroups.com
In gwt-user-2.4.0.jar CellTable.css, there is many css class like
.cellTableSelectedRow{
 ......
}

but I can not understand how this is applied to CellTable even I see the CellTable class source code.

Jens

unread,
Jun 21, 2012, 6:47:12 AM6/21/12
to google-we...@googlegroups.com
Its done in AbstractCellTable.renderRowValues(). This method asks the SelectionModel of the CellTable if a row is selected or not and applies the css class to the row if needed. When you click on a row in a CellTable the SelectionModel is updated using a default CellPreviewHandler. This is done in AbstractHasData (line 299 in GWT 2.4). 

-- J.

tong123123

unread,
Jun 21, 2012, 11:07:57 PM6/21/12
to google-we...@googlegroups.com
if the row is selected, I set its RowStyles to null as shown in attached file output.txt, this give me  the output as attached in output.png.

But I still do not know why when I return null in CellTable.setRowsStyles, the default style will be used (although this is what I want)!!
output.png
output.txt

Jens

unread,
Jun 22, 2012, 4:42:59 AM6/22/12
to google-we...@googlegroups.com
But I still do not know why when I return null in CellTable.setRowsStyles, the default style will be used (although this is what I want)!!

The JavaDoc indicates that the style names you return in this method are appended to the default styles of a row (extra styles). If you return null nothing will be appended.

-- J.
Reply all
Reply to author
Forward
0 new messages