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

304
Visualizações
Dynamically add a new row to ag-grid with dynamic (variable) columns

I'm trying to dynamically add a new row on button click event, on ag-grid on my ReactJS page.

Code below works for me, when the I've the fixed number of columns known at design-time..

let row ={
products1: "a",
products2: "b",
products3: "c"
}

gridApi.updateRowData(add: [row])

But I need to get this working as well, if the number of columns are variable and are only known at run time. Not sure if this is feasible in ReactJS/ag-grid?

Do I need to use array's map feature here?? So far, I've tried the below, but gives syntax error.

const rowArray = []

for(int index=0; index < myProductColumnsArrAtRunTime.length;index++)
{
    rowArray.map((myProductColumnsArrAtRunTime[i], myProductColumnsArrAtRunTime[i].category) => {myProductColumnsArrAtRunTime[i]}:  {myProductColumnsArrAtRunTime[i].category});                                                                                                     
}
gridApi.updateRowData(add: [rowArray])
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If the number of columns change after the initial state of the grid, you need to update the column definitions first. Refer documentation for updating column definition.

Later the 'Add row' button should add new rowData based on the new set of columns. This has to be done manually based on the different column structures you have.

about 4 years ago · Juan Pablo Isaza Relatório

0

To dynamically add a new row to the grid with variable columns use below code

Note: Here I have used functions from lodash library which starts from _

// GET GRID colDefs
  const colDefs = gridApi.getColumnDefs();
  const newRowObj = {};

  // LOOP OVER THE `colDefs` AND SET THE `null` DATA FOR EACH FIELD FOR THE NEWLY ADDED ROW
  _.forEach(colDefs, (eachColDef) => {
    const { field } = eachColDef;
    _.set(newRowObj, field, null);
  });

  // ADD THE NEW ROW TO THE GRID
  gridApi.updateRowData({
    add: [newRowObj],
    addIndex: 0, // YOU CAN PASS THE INDEX AT WHICH THE NEW ROW IS TO BE ADDED
  });
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