It really depends on the size of your list, you can take two approaches (neither is perfect), both involves adding a position
property to your GoAngular model (or creating a model specifically to track positions):
Let's make this our starting point:
[
{ title: 'Item A', position: 1 },
{ title: 'Item B', position: 2 },
{ title: 'Item C', position: 3 },
{ title: 'Item D', position: 4 },
]
If the list is small (in the hundreds of items), you can update positions as they change, so if 'Item B' was moved after 'Item C', you would update the position (using $set
) for items B & C:
[
{ title: 'Item A', position: 1 },
{ title: 'Item C', position: 2 },
{ title: 'Item B', position: 3 },
{ title: 'Item D', position: 4 },
]
Alternatively you could insert an item in the middle of two positions, this is more practical in large lists. If 'Item B' was again moved after 'Item C', you would update the position of only 'Item B'. In this example it would be (3+4) / 2 = 3.5:
[
{ title: 'Item A', position: 1 },
{ title: 'Item C', position: 3 },
{ title: 'Item B', position: 3.5 },
{ title: 'Item D', position: 4 },
]
Does that help?