I have a list with objects stored in a database. These objects are shown in a list and the user can drag and drop them to order them in a specific way. I want that specific order to be stored.
How can I do this in an efficient manner? I've thought of the following options:
Maintain an array with the desired order. Array can be stored locally (not an option in my current project) or online (extra table :(). I don't really like this solution.
Add a "priority" field to each object, and sort the objects by it. By dragging and dropping the priority of one object is changed to a value < the object above and > than the object beneath. There should be a big margin between those priority values though, or I should use halve numbers/float (infinite to platform's float definition). Else one might end up trying to decide what number is bigger than 2 and smaller than 3, for example. Update the updated object only.
Same as 2. but update ALL objects after a drag and drop action, and store them all. This feels a bit inefficient and unnecessary.
Am I missing the obvious? Is there a better way?