GWT: how to change row color in GWT Celltable

I have a combo table in GWT, I can change the color of a specific column to

celltable.addColumnStyleName(4, "bluetext"); 

but how can I change, for example, the color of line number 3

thanks

+6
source share
3 answers

You must provide a RowStyles object that returns css class names for each row. Thus, to set a specific color for a string, you need to define a css class with that color, and then force the RowStyles object to return this class for the corresponding strings.

I think you set this with cellTable.setRowStyles or something similar.

 cellTable.setRowStyles(new RowStyles<T>() { @Override public String getStyleNames(T rowObject, int rowIndex) { if (rowIndex == 3) { return "bluetext"; } else { return "normaltext"; } }); 
+15
source

If you need to update the color of a string based on a value changed in one of the cells, you can add the following code to the UPdater field of this cell:

 @Override public void update(int index, Object object, String value) { if (someConditionIsMet) { myTable.getRowElement(index).addClassName("redBackground"); } } 

In your CSS file add this style:

 .redBackground { background-color: red !important; } 
+2
source

To answer the last comment that the style is in the row element but not showing: Using setRowStyles (new RowStyles () ... The only way I got the styles is to use brute force. I had to remove the line from my List store. add it back to the same index and then update the RowModel for what it's worth.

+1
source

Source: https://habr.com/ru/post/906961/


All Articles