简体   繁体   中英

How to render a specific grid cell (GXT)?

How to render a specific grid cell from a grid in GXT (Java) ?

I want to validate the expression (as string) from the grid's cells, if the expression from the grid cell has an invalid syntax, than the corresponding grid cell's background should change in red, else the background should remain white.

Here is an example to render all the cells for a specific column:

getColumnModel().getColumn(cellColIndex).setCell(new AbstractCell<Object>() {
        @Override
        public void render(com.google.gwt.cell.client.Cell.Context context, Object value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<div style=\"background-color:red;\">");
            sb.appendHtmlConstant(value.toString());
            sb.appendHtmlConstant("</div>");
        }
    });

I want to render for a specific cell. Is there a way to do that?

In the cell renderer you've shown, check if it should display as red or not (and if so, use the background-color based on that logic).

Then, when that value changes, call store.update(...) on the row that needs the change, to ask the grid to re-render it and update the color.

There isn't a (good) way to modify already-rendered cell by hand - this is deliberate, as the grid might decide that a re-render needs to happen (a sort or filter operation, paging or scrolling, etc), in which case your custom styling would be lost. Instead, just update the cell's logic to reflect what you need, and tell the store/grid to update when the data changes.

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