I have a list of things with their ranking, and a page where a user can re-arrange the ranking of items in the list, how can i adjust the DB accordingly?
Example the user drags item 15 to row 4?
I can tell the database to change item 15’s ranking to 4, and items 4’s ranking to 5, but now i will have 2 items that have 5 as their ranking
Create a workflow, possibly backend, to run on a list. Every time an item is dropped, run the workflow on the list and make the rank of each item it’s current cell’s index.
I can’t find the source for what I read the other day but I believe the backend workflows are designed to be able to do hours worth of work without interfering with the performance of your app. The front end workflows are designed for making small data changes when it will benefit visual data being displayed to the user. But front end can handle up to 100 items or more if it to display a list of items or users sorted by rank.
Use states to create two lists, one below and including the moved item and one above minus the moved item:
Below list: Items 1-3 plus item 15
Above list: items 4-20 minus item 15
Set old list in DB to: “Below list” “merged with” “Above list”
You can create a second workflow if you’re moving an item “below” another item rather than “above” another item.
I tried to figure this out for like two hours yesterday and even built a plugin to reorder the items and give them back to bubble but the problem is still that you can’t seem to make changes to a list and the access each items’ index within the list so I would say with bubbles current constraints this cannot be done. The issue is it is trying to make a change to multiple items, editing its rank to equal its new index in the list, not just one list of items.
I am not using the plan that gives me access to the backend workflows so I can’t test that right now. But I think it is odd that you can’t say ‘for each’ item in the list, make changes to its ‘rank’ field and make that change a dynamic value. Maybe this could be brought up to bubble support as I agree it should be possible. Really they just need to update the make changes to a list to include indexOf or make current iteration within the list an available value to access.
I see @gbenchanoch has a possible solution which I will enjoy viewing. I finished a plugin that will accomplish what you are trying to do. It has to be approved by bubble which may take up to 72 hours.
Here is the example: