The app I am creating shows users a list of items which are all model instances. I want them to be able to sort the items however they would like using JQuery's sortable() method. This is implemented and working properly, but I need a way to save the order in which they are listed. This list is updated somewhat frequently, items being removed and new ones added.
My initial approach was to give the model a "position" column and each time a list item is moved within the list, change the position value of all items in the list. However, this would require me to get all the model objects every time 1 is sorted and apply a change to each one.
The only other way I could come up with was to give each a "weight" value instead of their actual list position. Leave enough space in between each value to fill in gaps. For instance, the weights are 10, 20, 30, & 40. If the user moves the fourth item to the second position, look at the first and second items and pick 15 as its weight. This, of course, will only work so long before all the weights will have to be recalculated in order to place an item.
Am I overthinking this? I don't expect high usage from this app, so the extra model calls using the position column won't really be a problem - but if there is a better, more efficient way to do this I would still prefer to do it that way.
Thanks :-)