RowReorder, disallow drag and drop ?

RowReorder, disallow drag and drop ?

korey03korey03 Posts: 3Questions: 1Answers: 0

Hello,
I'm using RowReorder extention and I want a row on top that can't be drag and drop then prevent an other row to replace it.
Is that possible?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,766

    See if this thread helps. Its not a trivial task but possible. The thread keeps the bottom row at the bottom. Try changing the last example in the thread to keep the row at the top.

    Kevin

  • korey03korey03 Posts: 3Questions: 1Answers: 0
    edited April 2020

    Thank you, that helped me a lot.

    I'm looking for a way to save the table state before moving a row and if a row is moved to the first one then we go back to its previous state.

    I tried something. Well... I don't understand, the first time when I drop the fourth row for example on the first one it works but not the second times.

    http://live.datatables.net/razobati/2/edit

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,766
    Answer ✓

    Without digging into your code I'm not sure what is going on either. One problem I noticed is you aren't disabling the top row from being moved. I fixed it here by changing your if statement to if (rowData[1] === 'owner') {, see here:
    http://live.datatables.net/razobati/4/edit

    You don't need to clear the rows and use rows().add() to re-add them. You can use the data that is available to the row-reordered event to revert the order. Basically you can apply the oldData value to each row that was reordered. Here is you example updated:
    http://live.datatables.net/juxunasi/1/edit

    Its actually a much simpler solution than the one I posted. In that example I wanted to swap the static row with the one that was dragged and dropped. You just want to revert back.

    Kevin

  • korey03korey03 Posts: 3Questions: 1Answers: 0

    I figured out where my mistake was.

    Thank you so much for your support.

This discussion has been closed.