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

289
Visualizações
In materia-ui table. When I click the button to expand the row, it expands all rows. How can i make only selected row will expand?

Row Click event expands all rows in the data table to display inner data of all rows

Expand button click expands all rows instead of selected row. Every time I'll click the button to expand the row1, it will also expand the second row. How can I fix this where only that specific row will expand?

<Table stickyHeader aria-label="sticky table">
  <TableHead>
    <TableRow hover>
      <TableCell>Title</TableCell>
      <TableCell>Created Date</TableCell>
    </TableRow>
  </TableHead>
  <TableBody>
  {data &&
   data((index) => (
    <TableRow hover>
      <TableCell>
        <IconButton
          aria-label="expand row"
          size="small"
          onClick={() => setOpen(!open)}
          >
          {open ? (
            <KeyboardArrowUpIcon />
          ) : (
            <KeyboardArrowDownIcon />
          )}
          </IconButton>
        </TableCell>
        <TableCell component="th" scope="row">
          {index.title}
        </TableCell>
        <TableCell component="th" scope="row">
          {new Date(
            index.createdDate.seconds * 1000
          ).toDateString()}
        </TableCell>
        <TableCell colSpan={6}>
          <Collapse in={open} timeout="auto" unmountOnExit>
            {index.text}
          </Collapse>
        </TableCell>
      </TableRow>
     ))}
   </TableBody>
 </Table>

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I was able to add the index to open function and allow only selected row expansion. It works as expected and below is my modified code

<Table stickyHeader aria-label="sticky table">
  <TableHead>
    <TableRow hover>
      <TableCell>Title</TableCell>
      <TableCell>Created Date</TableCell>
    </TableRow>
  </TableHead>
  <TableBody>
  {data &&
   data((index) => (
    <TableRow hover>
      <TableCell>
        <IconButton
          aria-label="expand row"
          size="small"
          onClick={() => setOpen(open === index ? -1 : index)}
          >
          {open == index ? (
            <KeyboardArrowUpIcon />
          ) : (
            <KeyboardArrowDownIcon />
          )}
          </IconButton>
        </TableCell>
        <TableCell component="th" scope="row">
          {index.title}
        </TableCell>
        <TableCell component="th" scope="row">
          {new Date(
            index.createdDate.seconds * 1000
          ).toDateString()}
        </TableCell>
        <TableCell colSpan={6}>
          <Collapse in={open == index} timeout="auto" unmountOnExit>
            {index.text}
          </Collapse>
        </TableCell>
      </TableRow>
     ))}
   </TableBody>
 </Table>

about 4 years ago · Santiago Gelvez 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