Css 如何向选定行DataGrid GWT中的列添加特定样式
Im为DataGrid设置自定义CssResource 表中的第一列是具有特定样式的有序列。 因此,当选择行时,我需要为order列设置另一种特定样式 诸如此类: 尝试使用Css 如何向选定行DataGrid GWT中的列添加特定样式,css,gwt,datagrid,Css,Gwt,Datagrid,Im为DataGrid设置自定义CssResource 表中的第一列是具有特定样式的有序列。 因此,当选择行时,我需要为order列设置另一种特定样式 诸如此类: 尝试使用 dataGrid.addCellPreviewHandler(新处理程序(){ @凌驾 公共void onCellPreview(CellPreviewEvent事件){ 如果(“单击”.equals(event.getNativeEvent().getType())){ table.getRowElement(event.
dataGrid.addCellPreviewHandler(新处理程序(){
@凌驾
公共void onCellPreview(CellPreviewEvent事件){
如果(“单击”.equals(event.getNativeEvent().getType())){
table.getRowElement(event.getIndex()).getCells().getItem(0.getStyle())
.setBackgroundColor(“#444444”);
}
}
});
注意:此代码用于
SingleSelectionModel
。如果您在MultiSelectionModel
中需要它,请对所有选定的行执行相同的操作。您可以覆盖列的。getCellStyleNames
方法:
Column<Object, String> numberColumn = new Column<Object, String>(new TextCell()) {
@Override
public String getCellStyleNames(Context context, Object object) {
if (selectionModel.isSelected(object)) {
return "boldStyle";
}
};
Column numberColumn=新列(new TextCell()){
@凌驾
公共字符串GetCellStyleName(上下文、对象){
如果(selectionModel.isSelected(对象)){
返回“粗体样式”;
}
};
我正在尝试.class.class方法.dataGridKeyboardSelectedRowCell.specificStyle{背景色:#444444!重要;}
但不起作用如果你有一个选择模型,你可以简单地添加一个SelectionChangeHandler。@AndreiVolgin如何在SelectionChangeHandler
中获取TableCellElement
来改变样式?实际上,有一个更简单的解决方案。请看我的答案。它不起作用?因为我使用了标记“!重要”对于样式。如何在代码中使用此标记设置样式?这很有效。谢谢,但不适用于NoSelectModel
。您在问题中说过“当选择一行时”。无论您如何决定是否选择一行,都可以用您使用的任何内容替换selectionModel.isSelected()。
Column<Object, String> numberColumn = new Column<Object, String>(new TextCell()) {
@Override
public String getCellStyleNames(Context context, Object object) {
if (selectionModel.isSelected(object)) {
return "boldStyle";
}
};