Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
Styling an edited cell using ag grid with React

I attempt to styles an edited cell by taking advantage of onCellValueChanged in colDef props but It does not work as attended. I am still new using Ag Grid and nothing about styling an edited cell is documented or maybe I missed it.

The code looks like this

const defaultColDef = useMemo<ColDef>(() => {
    return {
      resizable: true,
      headerComponent: "customHeader",
      onCellValueChanged: ({ colDef, api, node, column, columnApi }) => {
        colDef.cellClass = p => {
          return (p.colDef.field ?? p.colDef.colId) === (colDef.field ?? colDef.colId) && p.rowIndex === node?.rowIndex
            ? "dirty-cell"
            : "";
        };
        api.refreshCells({ rowNodes: [node!], force: true });
      }
    };
  }, []);

<AgGridReact
   ref={gridRef}
   defaultColDef={defaultColDef}
   onCellValueChanged={onCellChange}
   rowData={rows}
   columnDefs={columns}
   getRowId={param => param.data.id ?? param.data.virtual_id}
   components={{ customHeader: CustomHeaderCell }}
   onCellDoubleClicked={onCellDoubleClicked}
   onCellKeyDown={onCellKeyDown}
   rowClassRules={rowClassRules}
   gridOptions={{ tooltipShowDelay: 0 }}
   onDragStopped={onDragStopped}
/>

Hope my question is clear ! Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I used cellStyle in my code. It compares old and new value, if value is changed the css style is applied to that cell

onCellValueChanged = (params) => {
        if (params.oldValue !== params.newValue) {
            params.column.colDef.cellStyle = (value) => { 
                 return value.rowIndex.toString() === params.node.id 
                        ? { 'backgroundColor': '#9ac1fc' } : {} 
            };
            params.api.refreshCells({
                force: true,
                columns: [params.column.getId()],
                rowNodes: [params.node]
            });
        }
}

The code is in JS and you may need to convert in TypeScript, if some syntax error occured.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda