8

Hi I have some cells with custom rendering when I update the all data, the deltaRowDataMode does not hnadle the change of my cutsom cell rendering. Other cells of the updated row are correctly updated.

How can I give a clue to ag grid to compare correctly this custom cell

bodtx
  • 590
  • 9
  • 29

1 Answers1

4

I have just had the same issue and found a clue from the ag-grid documentation. In the Cell Renderer help doc it talks about the ICellRendererComp.refresh method:

// Mandatory - Get the cell to refresh. Return true if the refresh succeeded, otherwise return false.
// If you return false, the grid will remove the component from the DOM and create
// a new component in it's place with the new values.
refresh(params: ICellRendererParams): boolean;

and in the example further down:

// gets called whenever the user gets the cell to refresh
MyCellRenderer.prototype.refresh = function(params) {
    // set value into cell again
    this.eValue.innerHTML = params.valueFormatted ? params.valueFormatted : params.value;
    // return true to tell the grid we refreshed successfully
    return true;
};

I then implemented a refresh function on my CellRenderer as below without changing any of the cell contents:

statusCellRenderer.prototype.refresh = function (params) {
    //ensure the status cell\directive refreshes when the grid data is refreshed using deltaRowDataMode
    this.params = params;
    return true;
};

So in my case, I am refreshing the rowData of the grid on a polling cycling and I didn't want the grid to keep losing the selected row. I set the deltaRowDataMode and getRowNodeId properties on the gridOptions and then implemented the refresh function to make the cell re-render on a refresh. The refresh also re-renders a directive in my cell.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
sarin
  • 5,227
  • 3
  • 34
  • 63
  • This worked well for me. In my case I was trying to toggle a row to be a full width cell renderer via the isFullWidthCell callback in GridOptions. I found that using the usual `gridAPI.refreshCells()` did not initialize a full width cell renderer, and instead I used `gridAPI.redrawRows()` to initialize and tear down the full width cell renderer. See [Redraw Rows](https://www.ag-grid.com/javascript-data-grid/view-refresh/#redraw-rows) – nthaxis Feb 04 '22 at 01:24