I have a table with n fields, one of which is the 'order' (obviously it is sequential: 1, 2, 3, n ...):
id | ordem | nome
------------------------
1 | 1 | Fabio
3 | 2 | Gilmar
2 | 3 | Rodrigo
9 | 4 | Marcos
I'm developing a drag and drop table to change this order, so how do I keep this sequence always without skipping any numbers and repeating them?
To make it difficult, there will also be manual order, that is, the user accesses the registry and selects the desired position. Therefore, all records below this should be changed.
Note: My system provides 4 parameters after dragging: id, direction (forward / back), fromPosition and toPosition that could be used in the query.