简体   繁体   English

如何在选定的行DataGrid GWT中向列添加特定样式

[英]How to add specific style to column in selected row DataGrid GWT

Im set custom CssResource for DataGrid. 我为DataGrid设置了自定义CssResource。

First column in table is ordered column with specific style. 表中的第一列是具有特定样式的有序列。 So when row is selected i need set another specific style for the order column. 因此,当选择行时,我需要为订单列设置另一种特定样式。

Something like that: 像这样:

在此处输入图片说明

You can override .getCellStyleNames method for your column: 您可以为列覆盖.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";
    }
};

Try with AbstractHasData#addCellPreviewHandler() . 尝试使用AbstractHasData#addCellPreviewHandler()

dataGrid.addCellPreviewHandler(new Handler<T>() {

    @Override
    public void onCellPreview(CellPreviewEvent<T> event) {
        if ("click".equals(event.getNativeEvent().getType())) {
            table.getRowElement(event.getIndex()).getCells().getItem(0).getStyle()
                    .setBackgroundColor("#444444");
        }
    }

});

Note: This code is for SingleSelectionModel . 注意:此代码用于SingleSelectionModel If you need it for MultiSelectionModel then do same thing for all selected rows. 如果MultiSelectionModel需要它,则对所有选定的行执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM