Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT:how to change row color in GWT Celltable

Tags:

gwt

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

like image 565
junaidp Avatar asked Jan 26 '12 18:01

junaidp


3 Answers

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";
        } 
    });
like image 194
Riley Lark Avatar answered Nov 07 '22 16:11

Riley Lark


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;
}
like image 41
Andrei Volgin Avatar answered Nov 07 '22 16:11

Andrei Volgin


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.

like image 23
user1776933 Avatar answered Nov 07 '22 15:11

user1776933