Dynamic styles for GWT cellTable cells

2019-01-29 03:31发布

I'm having an issue using GWT. I'm building the columns of a cellTable and I want the style of a cell to depends of the value of that cell:

Column<MyProxy, MyProxy> editButtonColumn = new Column<MyProxy, MyProxy>(new ActionCell<MyProxy>("", new ActionCell.Delegate<MyProxy>() {
        @Override
        public void execute(MyProxy record) {
            if (object.isEditable()) {
                doSomething(record);
            }
        }
    })) {
        @Override
        public MyProxy getValue(MyProxy object) {
            if (object.isEditable()) {
                this.setCellStyleNames("editButtonCell");
            }
            return object;
        }
    };

I've checked in debug mode the style "editButtonCell" is applied correctly. But in the HTML generated, the style is missing everytime for the FIRST ROW... It looks like a GWT bug, but maybe you folks have a better explanation.

1条回答
啃猪蹄的小仙女
2楼-- · 2019-01-29 04:00

I haven't checked but most probably the opening of the cell has already been generated by the time getValue is called, so setCellStyleNames will only apply to the remaining cells in the column.

The right way to do it is to override getCellStyleNames of the column to return the CSS class name or not depending on the cell value.


BTW, you can then extend IdentityColumn as the getValue then becomes trivial.

查看更多
登录 后发表回答