Andrei Mihuț
Andrei Mihuț

Reputation: 47

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?

Upvotes: 0

Views: 663

Answers (1)

Colin Alworth
Colin Alworth

Reputation: 18331

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.

Upvotes: 1

Related Questions