I found a way to build primitive sorting into my app by adding a “Display Order” field (of type “number”) into my table for a list of items I want to show the user.
The Display order value is set when the user adds a new item: by searching all items of the same type, finding the highest display order value (using order by during search and getting the display order value of the first item) and then setting the display order value of the new entry to the result of the above search + 1.
For reporting, I’m able to display the data by display order, and I’m able to modify the Display Order as well. An increment event on a button increases the display order by 1. A decrement event does the opposite.
I display the data to the user ordered by display order AND also by modified date (so that if two items with the same display order value are present, the most recently modified shows above others with the same display order value).
I could just leave it like this.
Two issues:
-
Ideally there should never be the same display order value present twice in the database. If an item’s display order changes, the item above and below should have a corresponding change to its display order.
-
If an item is deleted, it leaves gaps in the display order value. Ideally the display order of all items above this item should change accordingly.
I’m really unsure how I would go about this.
Any Engineers out there that can provide some insight?
Here is a video of my app to show you everything I described above: