问题描述
我在使用 GWT 时遇到问题.我正在构建 cellTable 的列,我希望单元格的样式取决于该单元格的值:
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;
}
};
我在调试模式下检查了样式editButtonCell"是否正确应用.但是在生成的 HTML 中,第一行的样式每次都丢失...看起来像是 GWT 错误,但也许你们有更好的解释.
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.
推荐答案
我还没有检查,但很可能在调用 getValue
时单元格的打开已经生成,所以 setCellStyleNames
只会应用到列中剩余的单元格.
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.
正确的做法是覆盖 getCellStyleNames
返回CSS 类名与否取决于单元格值.
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.
顺便说一句,您可以将 IdentityColumn
扩展为 getValue
然后变得微不足道.
BTW, you can then extend IdentityColumn
as the getValue
then becomes trivial.
这篇关于GWT cellTable 单元格的动态样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!