简体   繁体   中英

How to add specific style to column in selected row DataGrid GWT

Im set custom CssResource for DataGrid.

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:

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() .

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 . If you need it for MultiSelectionModel then do same thing for all selected rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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