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

169
Visualizações
React Drag and Drop 2 fields with the same values

To contextualize, I have a trip that has for attributes points of interest that are assigned to it and are sorted by a rank field that allows us to display them in a desired order.

I have a problem, I set up a drag and drop system on my table of points of interest but when I move a cell it can have the same rank as the cell to which it is moved. This is not possible for us, I would like to know if there is a solution to make it impossible that two cells have the same rank or that 2 ranks with the same value are updated.

See the screen for the table :

table

My code to update a rank :

const { mutate: changeRank, isSuccess: changeRankSuccess } = useMutation(
async ({ pointTrip, rank }) => {
  let url = `http://localhost:443/api/pointTrip/${pointTrip}`;
  await axios
    .put(url, { rank })
    .then((res) => {})
    .catch((err) => {
      console.log(err);
    });
},
{
  onSuccess: () => {
    queryClient.invalidateQueries(queryKey);
  },
}

My code for change the rank on drag end :

const handleDragEnd = (result) => {

if(!result.destination) {
  return;
}
let tempPoi = [...trip.pointsOfInterest];
let [selectedRow] = tempPoi.splice(result.source.index, 1);
changeRank({pointTrip: selectedRow.PointTrip.id, rank: result.destination.index + 1});

Can you help me ?

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