1

The problem I have is this: I have a list of items. Each item has multiple properties. I have a view where I display all items and I have a view where I display the items based on values in properties. Now, I would like to allow the user to sort the items (drag-drop). When users sorts the items in the view that displays all of them (no filters), all is fine, but then when they select a filter, change the order while in the filter, and remove the filter - things gets messed up because order number while with filter doesn't match the one without the filter.

My thought was to increment the order value by 10000 and always position the item in the middle of where it was left. So, if I drop an item 4 with Order 40000 between items 2 and 3, the new order for item 4 will be 25000. This way even if I have a filter turned on, and items are missing from the list, and the list is re-ordered, the change of getting the same order number after removing the filter is small.

Example:

Full list:

Item 1 - 10000 Item 2 - 20000 Item 3 - 30000 Item 4 - 40000 Item 5 - 50000

Filtered list:

Item 1 - 10000 Item 2 - 20000 Item 4 - 40000

Filtered list re-ordered:

Item 1 - 10000 Item 4 - 15000 Item 2 - 20000

Full list re-ordered:

Item 1 - 10000 Item 4 - 15000 Item 2 - 20000 Item 3 - 30000 Item 5 - 50000

Now, if I move Item 2 above item 4 again, Item 2 will get 12500. The problem I am seeing is that if keep shuffling two items it will very soon run out of empty spots and will be 1 (rounded). It looks like that would happen after 14 order changes of two items which are next to each other. (log base 2 of 10000).

Do you have any ideas what would be a better approach to fix this problem? I was also thinking about storing PreviousItemId and NextItemId on each item and recalculate on each position change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.