Yes, fighting this issue too. My users will be adding, deleting and re-arranging items in repeating groups and I would like a âsort orderâ field to be recalculated every time? Perhaps @mishav knows how - can this maybe be done with âlist of numbersâ? or in any other way.
I know this can be done with API workflow, but am interested in a more instant solution
Iâm not sure how you will pull this off without using a schedule workflow on a list since you will have to run a workflow (update field values) on a list.
Even if youâre using Javascript to modify a list of numbers as youâre thinking at the end you will have to write this to your database.
Iâve done this before with the schedule a workflow on a list action. Basically you first need to store in a custom state the order number of the item to be deleted.
Then you delete the selected item.
You schedule an workflow on a list. The list will be a search for all items whose order number is greater than the deleted order number. (You only need to update those items below the deleted item, i.e. u want to shift those below up)
In the schedule workflow action you make change to the current item by decreasing its order number by 1.
The sort numbers do not have to be whole numbers. The easiest (might not be best) method for this would be to use the âCurrent cellâs index #â as a dynamic text element on the RG (must not be within a group, has to be âonâ RG base layer). Then the sort field:
First created thing in RG is given sort_order of 1, the next is given sort_order 2 and so on.
When a person deletes an entry, no big deal, the RG cell is removed and the sort order that shows to the end user is just the Current cellâs index # (always 1-x in single digit order). When a new thing is added to the middle of the RG between items 2 and 3 for instance, you would use the average of the two points and set the sort_order as 2.5
This scales infinitely since Bubble can store a calculated value over 10 decimal points. (2.25, 2.125, etc)
@philip This might work if you donât care about the order numbers being non whole numbers.
The poster didnât say if the order numbers are important or theyâre just a means to sort the items.
In my specific application I needed the order numbers to be consecutive whole numbers.
This is because I was using this to get the next/previous element in my list from an external api call. So if I wanted to get the next element I will add 1 to the current element order and use that order number to retrieve the item. So having decimal point order numbers wouldnât cut it for me.
If I was using non whole numbers I would have to do a search for all items greater than the current order. Sort them descending and pick the fist item. But I thought this was too cumbersome.
I think the approach one chooses will depend on their context. In my case the deletion operation will rarely occur but the search was going to be very frequent as my users will be making api calls to move from one item to the next one at a time. So it was better moving the complexity to the deletion instead of the searching.
Also my list is always going to be less than 50 so the workflow on list wasnât going to be expensive.
Nigel, would be interested in knowing more about a linked list option if possible?
Closest thing to a solution i have come up with so far is a workflow that simply swaps numbers using a +/- button. Works well as long as numbers are in sequence, but what to do when an item is deleted and numbers are no longer in sequenceâŚ
FYI all in this. I need the sequence to be in order at all times and instantly, but not nessecarily whole numbers and users do not need to see the numbers. So maybe I will try out @philip 's suggestion.