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

125
Visualizações
Drag and drop with Antd's Tree table

I am trying to make a tree table reorderable via drag and drop.

Here's the render for easier visualization:

enter image description here

I am also using React-DnD.

Here's a piece of my code:

const moveRow = useCallback(
  (record: StructureElement) => (dragIndex, hoverIndex) => {
    // console.log(record.name, dragIndex, hoverIndex);
    const dragRow = sortableData[dragIndex];
    if (!dragRow) {
      console.log(sortableData, dragIndex);
    } else {
      console.log('drag', dragRow.name, 'hover', sortableData[hoverIndex].name);
    }
    // todo - change the order in array
  },
  [sortableData],
);

<StyledTreeTable
  components={components}
  dataSource={sortableData}
  onRow={(record, index) => {
    return {
      index,
      moveRow: moveRow(record as StructureElement),
    };
  }}
/>

So the problem is, my sortableData looks like this:

[
  { name: 1 },
  { name: 2 },
  {
    name: 3,
    children: [
      { name: 11 },
      { name: 22 },
      { name: 33, children: [{ name: 111 }, { name: 222 }, { name: 333 }] },
    ],
  },
];

So my objects can have more objects nested in children.

But moveRow function doesn't see it this way. For it, ABSTRACT_STATE_4 is of index 4. So when I try to reorder the array, I try to do this: data[4], which results in undefined.

Is there a way I can reorder the items in tree table with drag and drop, that I haven't found yet?

The only way I see of solving it now, is to recreate the array the way hover and drag indexes match. But that's a lot of seemingly unnecessary work.

Is there a way to get the record I am hovering over, like I'm getting hoverIndex?

about 4 years ago · Juan Pablo Isaza
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