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

221
Visualizações
How to reset row indexes on filtered values in React-Table?

I'm trying to implement a feature in my table where I need the current row index after a filter is applied in React-Table.

The example below, shows the problem, by clicking on a radio button, that particular row index is selected, and displayed at the bottom of the table.

If a filter is applied and the user selects, say the first or second row, the index shown is of the original unfiltered data.

Example: https://codesandbox.io/s/react-table-window-multiple-selection-tools-qsth1

After a filter is applied, and 4 results are shown, then by selecting the first row, the index should be 0.

Hope that makes sense.

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

0

You didn't provide all the scenarios, but I think it works fine, please check it and tell me the result.

const ColumnFilter = ({ column }, setSelectedRadio) => {
  const { filterValue, setFilter } = column;
  return (
    <input
      style={{ width: "100%" }}
      value={filterValue || ""}
      onChange={(e) => {
        setFilter(e.target.value);
        setSelectedRadio([]);
      }}
    />
  );
};


const RadioCheckbox = ({ cell, selectedRadio, handleChange, filteredRows }) => {
  let itemValue;
  filteredRows.map((item, index) =>
    item.id === cell.row.id ? (itemValue = index.toString()) : null
  );

  return (
    <input
      name="radio-selection"
      type="radio"
      onClick={handleChange}
      value={itemValue}
      defaultChecked={selectedRadio.includes(itemValue)}
    />
  );
};

 // In App function      
  const columns = React.useMemo(
    () => [
      {
        id: "radio",
        Header: "on/off",
        Cell: (props) =>
          notAllowedRows.includes(props.cell.row.index) ? null : (
            <div>
              <RadioCheckbox
                cell={props.cell}
                filteredRows={props.filteredRows}
                selectedRadio={selectedRadio}
                handleChange={handleSelectedRadioChange}
              />
            </div>
          ),
        width: 60,
        Filter: (props) => ColumnFilter(props, setSelectedRadio)
      },
      {
        Header: "Row Index",
        accessor: (row, i) => i,
        width: 95,
        Filter: (props) => ColumnFilter(props, setSelectedRadio)
      },
      {
        Header: "First Name",
        accessor: "firstName",
        Filter: (props) => ColumnFilter(props, setSelectedRadio)
      },
      {
        Header: "Last Name",
        accessor: "lastName",
        Filter: (props) => ColumnFilter(props, setSelectedRadio)
      },
      {
        Header: "Age",
        accessor: "age",
        width: 50,
        Filter: (props) => ColumnFilter(props, setSelectedRadio)
      },
      {
        Header: "Visits",
        accessor: "visits",
        width: 60,
        Filter: (props) => ColumnFilter(props, setSelectedRadio)
      }
    ],
    [selectedRadio]
  );
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