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

103
Visualizações
React table pre select rows

I'm trying to preselect rows in my table but the table won't refresh unless there are changes to the actual data itself. Is there a method to reinit the table that doesn't involve changing the data?

It's also completely possible that my method for approaching this requirement is wrong and there may be a better way? I've created an example sandbox here:

https://codesandbox.io/s/mock-preselected-rows-data-t36nl?file=/src/App.js

In this you can see I have a mock response from my server for determining what rows should be selected. I'm then grabbing the data to compare to see if any of the items from the mock response exist in the data and if so push them to a new obj which is then fed into the intialState for selectedRowIds

Any guidance appreciated.

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

0

Seems your work is all working. The short answer to your question.

As long as you want the user see something, in a React way, it needs to be contained in a state, or state derivative. In your case, it's a cell data wrapped in row and in a table.

So you can't avoid selecting it without touching the data. Unless you don't want user see the change.

Although the checkbox doesn't seem to be part of the original data stream, when you develop on it, you have to make it part of the data. To be honest, it's easy you make it part of the data, because by the time you want to refresh the table, ex. selecting or de-selecting, or deleting a row, you want everything refreshed. Unfortunately it's very difficult to do local refresh with a table in React. It's possible, but very difficult, because most of the design is based on either prop or context.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can also refactor your handleSelectedRows function.

// Find row ids and compare them with our 'preSelectedTheseItems' array.
  const handleSelectedRows = () => {
     const preIds = preSelectTheseItems.map(item => item.collectibleId)
     return data?.filter((collectibleRow, index) => preIds.includes(collectibleRow.collectibleId));
  };

Example : codesandbox

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