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

336
Vistas
Updating defaultColumnDefs doesn't rerender the Grid

I'm trying to add a button that toggles sorting in the grid, when I click on the button, and console log the defaultColumnDefs that sortable got toggled but the grid never rendered.

import React, { useState } from 'react';
import { AgGridReact } from 'ag-grid-react';
import 'ag-grid-community/dist/styles/ag-grid.css';
import 'ag-grid-community/dist/styles/ag-theme-alpine.css';
function App() {

const [sort, setSort] = useState(false);

const [rowData] = useState([
  { make: 'Toyota', model: 'Celica', price: 35000 },
  { make: 'Ford', model: 'Mondeo', price: 32000 },
  { make: 'Porsche', model: 'Boxter', price: 72000 },
]);

const [columnDefs] = useState([
  { field: 'make' },
  { field: 'model' },
  { field: 'price' },
]);

const [defaultColDef, setDefaultColDef] = useState({
  sortable: sort,
});

const sortHandler = () => {
  setDefaultColDef({ ...defaultColDef, sortable: !sort });
  setSort(prev => !prev);
};

console.log(defaultColDef);

return (
  <div>
    <div className="ag-theme-alpine" style={{ height: 400, width: 600 }}>
      <AgGridReact
        columnDefs={columnDefs}
        defaultColDef={defaultColDef}
        rowData={rowData}
      ></AgGridReact>
    </div>
    <button onClick={sortHandler}> {sort ? 'No sort' : 'Sort'} </button>
  </div>
);
}

export default App;

What might be wrong?

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

0

The sort property is stateful meaning that you can change them without having to update the column definition. To do this, you call the columnApi method applyColumnState()

See documentation on Column State

Here is an example that dynamically changes the sorting of the grid

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