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

204
Visualizações
Material-UI Table select all per page pagination

Is it possible to select items only on the current page / per page in the Table?

https://codesandbox.io/s/ebnf3?file=/demo.js

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

0

You can look at how the rows get sorted and filtered inside the TableBody below, just take the part where it filter to the handleSelectAllClick function:

<TableBody>
  {/* if you don't need to support IE11, you can replace the `stableSort` call with:
      rows.slice().sort(getComparator(order, orderBy)) */}
  {stableSort(rows, getComparator(order, orderBy))
    .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
    .map((row, index) => {
      return (...);
    }
const handleSelectAllClick = (event) => {
  if (event.target.checked) {
    const newSelecteds = stableSort(rows, getComparator(order, orderBy))
      .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
      .map((n) => n.name);

    setSelected(newSelecteds);
    return;
  }
  setSelected([]);
};

At this point, it's almost working except that you can't clear all the selection because the Checkbox's state inside the table header depends on the number of rows selected, it can't be unselected because you only select the rows in 1 page, not all rows. You can fix it by taking control of the Checkbox and make it always change state between the 2 options (select/unselect):

const [value, setValue] = React.useState(false);
<Checkbox
  color="primary"
  // indeterminate={numSelected > 0 && numSelected < rowCount}
  checked={value}
  onChange={(_, value) => {
    setValue(value);
    onSelectAllClick(_, value);
  }}
  inputProps={{
    "aria-label": "select all desserts"
  }}
/>

Codesandbox Demo

about 4 years ago · Juan Pablo Isaza Relatório

0

Editing the handleSelectAllClick to the following should work:

 const handleSelectAllClick = (event) => {
    if (event.target.checked) {
      const newSelecteds = stableSort(rows, getComparator(order, orderBy))
      .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
      .map((n)=>n.name) 

      setSelected(newSelecteds);
      return;
    }
    setSelected([]);
  };
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