i have a celltable in GWT, I can change color of a specific column by this
celltable.addColumnStyleName(4, "bluetext");
but how can i change for example color of row No 3
Thanks
You have to provide a RowStyles
object that returns css class names for each row. So, to set a particular color for a row, you'd have to define a css class with that color, and then cause your RowStyles
object to return that class for the relevant rows.
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";
}
});
If you need to update row color based on a value changed in one of the cells, you can add the following code to the fieldUpdater 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;
}
To answer the last comment that the style is in the row element but is not being rendered: Using setRowStyles(new RowStyles() ... The only way I got the styles to appear was to use brute force. I had to remove the row from my List store, add it back to the same index and then refresh the RowModel. For what it's worth.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With