Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

css - Dynamic styles for GWT cellTable cells

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...