Search code examples
cssgxt

GXT3 - Change grid cell background color dependent on value (without CSS classes)


In GXT2 it was possible to change a cell's background color within the GridCellRenderer's render method. With GXT3 this is not possible anymore and the suggested approach is to use a GridViewConfig and override the getColStyle method.

My problem with this appoach is that I don't want to use css classes here but directly manipulate the cell's style as the desired background colors are only known at runtime.

My first idea was to do something like grid.getView().getCell(rowIndex, colIndex).getStyle().setBackgroundColor(...) within getColStyle but the returned cell always seems to be null here.


Solution

  • I've found a solution by myself:

    I had to override com.sencha.gxt.widget.core.client.grid.GridView#doRender and append some custom SafeStyles to the cell dependend on the model. To make it more flexible, I introduced also an inheritance of the GridViewConfig to do this job.

    I hoped that there would be a simpler solution but at least it is one.