GWT:how to change row color in GWT Celltable

2020-07-13 09:30发布

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

标签: gwt
3条回答
冷血范
2楼-- · 2020-07-13 09:34

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;
}
查看更多
不美不萌又怎样
3楼-- · 2020-07-13 09:51

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";
        } 
    });
查看更多
放我归山
4楼-- · 2020-07-13 09:59

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.

查看更多
登录 后发表回答