I’ve got a site (here) that lets users publish labs. I’m looking at adding a feature where users can customise the order that their labs appear in. To be clear, I mean that they can manually control the order, not that they pick sort by name/date/popularity/etc.
This feels like it shouldn’t be too tricky but I’m finding it harder to implement that I expected. My initial attempt adds an order
field to the Labs
table. This is easy enough to sort on for display. But making changes to the order is a little tricky as a move needs to change order
on at least two rows. Also, if a lab is deleted, that results in a gap, and the code needs to be more complicated to cope with this.
In a lot of ways it would be easer to just join the IDs together in the desired order, forming a string like “7,3,1,8,2” and save that in the database – but that feels like an anti-pattern.