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

171
Visualizações
refresh AgGrid and reselect last selected row

I am trying to refresh ag grid and reselect the last row before update.

This is my AG grid component.

  onCellClicked = params => {console.log(params)
    let node = params.node;

    Promise.all([
      node.setSelected(true, true),
      this.props.actions.selectMarketingProspect(node.data),
      this.props.actions.getMarketingCustomerNotes(this.props.dealerID,node.data.id)
    ]);
  };

      <AgGridReact
          columnDefs={columnDefs}
          defaultColDef={{
            resizable: true,
            sortable: true
          }}
          rowSelection='single'
          getRowNodeId={data => data.id}
          deltaRowDataMode={true}
          frameworkComponents={frameworkComponents}
          rowClassRules={this.state.rowClassRules}
          detailCellRenderer={detailCellRenderer}
          onFirstDataRendered={this.onFirstDataRendered}
          onGridReady={this.onGridReady}
          onSelectionChanged={this.onSelectionChanged}
          onCellClicked={this.onCellClicked}
          sideBar={toolPanelOptions}
          onModelUpdated={this.onModelUpdated}
      />
    </div>

Any ideas?

Based on what I read on the docs I believe that node.setselected should do the trick but I cant quite get there. Any help will be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can keep track of the last selected RowNode ids by listening to the selection changed event:

const [selectedRowIds, setSelectedRowIds] = React.useState<string[]>([]);
<AgGridReact
  onSelectionChanged={(e) => {
    const selectedNodes = e.api.getSelectedNodes();
    if (selectedNodes.length === 0) return;

    const selectedRowIds = selectedNodes
      .map((n) => n.id)
      .filter(Boolean) as string[];

    setSelectedRowIds(selectedRowIds);
  }}
  {...}
/>

Then when you want to select it again, use GridApi.getRowNode(id) to get the RowNode you want to select and call RowNode.setSelected(true) to select it:

selectedRowIds.forEach((id) => {
  gridApi?.getRowNode(id)?.setSelected(true);
});

Codesandbox Demo

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