Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda