Drag-and-drop ordering perfection

Andrew has an great tutorial on implementing drag-and-drop functionality in repeating groups, but it’s primarily a quick start guide that swaps two items in a list with each other’s position, which is probably not ideal for most use cases.

(For example, if you have 3 items, ABC, and drag A to the C position, the order becomes CBA. The desired behavior would be BCA.)

As such, I’d like to ask how you all managed to solve this. I see that @Scott suggested a clever solution involving averages, though maybe there’s a cleaner way?: Drag - Drop Reorder Your Repeating Group

I’m guessing @emmanuel has a solution here too, as this type of drag-and-drop ordering was integrated into workflows.

Thanks in advance! If I get no replies, I’ll keep working on the problem.

1 Like

Pondering this more, it seems the cleanest solution would look something like this:

A counter is created, infinitely increasing (i++).

For the following list of items:
1 Tiger
2 Cat
3 Mouse
4 Dog
5 Lemur

When moving “Cat” To “Dog” down the list (ie. item 2’s order < item 4’s), workflow is:

-Cat (2) new order becomes Dog (4)
-Dog (4) order becomes Dog (4) - 1 (so 3)
-Everything < Dog order is -1

When moving “Dog” To “Cat” up the list (ie. item 2’s order > item 4’s), workflow is:

-Dog (4) new order becomes Cat (2)
-Cat (2) order becomes Cat (2) + 1 (so 3)
-Everything > Cat order is +1

As long as no two numbers are the same, this should work. Now I just have to adjust to the syntax/format Bubble uses.

I’ll keep this thread posted if I ever get this thing working. If there’s a way to select everything before or after a specific integer, I’d love to know.

1 Like

How did this go?

Still not working, sadly. After a long period of frustration I shelved this for now, though I’m still convinced it’s a solvable problem. If anyone knows how to select everything after/before a cell’s value, then change those values on certain conditions, that would probably help a lot.

In my workflow, I tried using “Only When” to say “hey, if this thing I’m moving’s cell’s order is greater or less than the thing I’m replacing it with, add/subtract 1.” It didn’t work as expected, which is probably user error.

1 Like

positions > dropped in cells index -1 become there position + 1 (this will take care of the the higher positions and the one already in the dropped in cell. Then dragged item gets dropped cells index.

This topic was automatically closed after 70 days. New replies are no longer allowed.