ag-grid cellRendering with deltaRowDataMode
Asked Answered
D

1

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

Dunno answered 11/4, 2018 at 11:43 Comment(1)
Please share a snippet more clearanceConfessor
J
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.

Justinjustina answered 15/3, 2019 at 13:14 Comment(1)
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 RowsGalvanometer

© 2022 - 2024 — McMap. All rights reserved.