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

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

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 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