You can take a look at the following tutorial to see how to handle row moving and persist the row order (in JavaScript/Node.js):
https://code.daypilot.org/95340/react-activity-planning-system-node-express-postgresql
The order is stored using two DB field (ordinal, ordinal_priority) and the reordering is done in two steps - first the row is inserted at the specified location and then the fields are compacted (spaces in ordinal values removed, duplicate ordinal values changed, and ordinal_priority made the same).
You can find the same logic implemented in PHP in this tutorial:
https://code.daypilot.org/93862/html5-gantt-chart