Forum Academy Marketplace Showcase Pricing Features

List Shifter Sorting Oddity

I have a drag and drop list sorted on an Order field. So, if an item gets dropped between items 1 and 2, the dropped item is assigned an Order of 1.5. To avoid the fractions getting long and messy, I’m trying List Shifter to refactor the list i.e. updating each item’s Order to be equal to its index.

I’ve got this set up so List Shifter’s data source is Do a Search For… sorted by Order. In turn, my repeating group’s data source is List Shifter. I’ve also got a button that does the List Shifter iteration to refactor my list.

All is fine and dandy. When an item’s Order value changes, the list re-sorts and the item reappears in the correct order. And when I click the button to refactor, the iteration happens and the Order values are reset to the cell’s index value.

However, after refactoring, List Shifter’s behavior changes. The list still displays in the repeating group but it doesn’t re-sort when an item’s Order value changes. I’ve tried various ways to reset List Shifter. Haven’t found anything that works except resetting the page which is disruptive.

Help.

Yeah, @keith, put that turkey leg down and help, man. :wink:

1 Like

Hey @jfranzlien: The value of whatever expression you put in List to Shift is simply evaluated whenever the expression’s result changes (and then it is echoed to the Original and Shifted List outputs). Note that it’s not me that decides if the expression’s result has changed, it’s Bubble. Of course, the plugin will run its update function whenever ANY of its fields have changed, so we could leverage that (I describe how to do this below).

I suppose there are cases in Bubble that might seem like they should change the result of the expression, but do not.

There’s no ACTION for forcing List Shifter to run its full update function (the RESET action is close to this, but it doesn’t re-evaluate the List to Shift, it just removes transformations to Shifted List). Aside: Official documentation for the RESET action, which doesn’t appear anywhere in Bubble, but is in the code:

RESET: “Execute this action to reset List Shifter’s Shifted List to its initialized state. Transformations such as SWAP Items are cleared and most other values revert to their initial state. Note: This action DOES NOT clear List Shifter’s Processed List, Custom Value, and Custom List as these values are only published in response to your own workflow actions.”

SOLUTION:

If you’re in a situation where you need to force List Shifter to run its update function again because you consider the expression to have changed (even though Bubble might not), you can “trick” List Shifter into running its update function by just hijacking one of its unused fields to be a dynamic expression and then make that expression change.

The easiest way I can think of is to use the “start at” or “increment by” fields under “GENERATE NUMERIC LIST” (these affect nothing if you’re not using “Make a numeric list”). So what I’d do is add a numeric custom state to your List Shifter like this and use it as the value for “start at”:

And now, anytime you want to force List Shifter to update, you can just change that value, like:

Note that, if this doesn’t fix your problem, your problem is not what you think it is.

Now there’s gravy all over my keyboard, @mikeloc!

1 Like

Thanks! Didn’t even realize I was posting on Thanksgiving. I’m Canadian and our Thanksgiving holiday is in October.

I set up the workaround you suggest and confirmed by watching the reset variable change. But alas, it made no difference. After running an iteration, the list in my repeating group still no longer sorted when I changed a value in the sort field.

What did work was adding a workflow step after the iteration to Display List in a Repeating Group including search and sort specs. Nothing special, just populating the repeating group using a Bubble command.

The behavior indicates that the Bubble side is paralyzed somehow by the iteration but works again when Bubble repopulates the repeating group itself.

So, no worries. I’ve got a simple workaround and List Shifter is doing exactly what I need it to do.

Thanks again.

1 Like

Argh. I spoke too soon. The iteration works perfectly once. Then something goes wrong between List Shifter and Bubble and the list won’t redisplay (resort) when the user changes the value in the sort field (Order). The only way I can see to make it work is somehow running the List Shifter iteration once when the user is leaving the page.

@jfranzlien this is all way too vague for anyone to assist you. You’ll have to share your editor for folks to understand what you’re doing and suss out where you’re going wrong. (It’s highly unlikely there’s any actual problem with List Shifter and a high probability that this is a user headspace error.)

EDIT: Another thing to look at and think about — If you have some procedure that seems to work right the first time, but then doesn’t the next, and then “sort of” works the third time, this is a symptom of a synchronicity problem. (Something you think is synchronous is NOT actually complete yet and some subsequent action you are taking is being done at the wrong time. You don’t say how you are sorting your list, but if you’re using LS’s SORT action, that action is NOT synchronous with respect to most other (meaning non-List-Shifter) actions in a workflow, which is why LS will throw the Sort Complete event to let you know that the sorted list is actually available.)

image
Here’s the setup of my repeating group using ListShifter’s Original List as its data source.

image
My repeating group has three columns: 1. the name of my thing, 2. a temporary numeric field I’m using to sort on, and 3. the cell’s index.


List Shifter is doing the search and sort.

image
I have a button that initiates a List Shifter iterate process.

image
The iteration process sets my sort field (called Deleteme so I remember it’s temporary) to the iteration’s current index.

image
Next, I change Sort By numbers (Deleteme). Each time I do, the list re-sorts. What I’m doing is entering fractional numbers to position one record between two other records. This simulates the behavior of a page in my app which has drag and drop lists (Kanban boards, etc.). The program works pretty well but if a list is used for a long time, the fractions get really long and anomalies can develop.

So, I was thinking it would be good once in a while to reset the Sort By field to equal the index.

When I click on Process List it invokes the List Shifter iteration which does the job very nicely.

image
However, post-iteration, I start revising the Sort By numbers, same way as I did before. But this time, as you can see, sorting is no longer working. I’ve changed a bunch of numbers in the Sort By field but nothing happens.

Did I miss something? Or is there a better way to do this?

Thanks.

This isn’t really a use case for List Shifter. If you’re interested in a more convenient way to do this, see (end of video):

The drag/drop feature doesn’t work for every case in the new responsive editor because Bubble really borked things up there via-a-vis plugins, but paid customers get priority in making this feature work for their specific use case(s).

Read and learn about Floppy here FLOPPY: Plugin for localStorage, sessionStorage, IndexedDB storage, List Creation/Manipulation, Iteration, and More! Now with even more video docs!

(It’s on sale for $7 right now which is just insane.)

Thanks, Keith. Just to be clear, there was no drag and drop in my example above. All I was doing was resetting the values in a sorted column in a Repeating Group to their cell index values. It worked fine with one hitch – after a successful iteration, the rows in the Repeating Group would no longer sort.

Oh well. I gave up and got Floppy as you suggested and started working with it. Then, I was interrupted by an emergency. I discovered the Font Awesome icons in my application were all messed up in both Dev and Live. The forums blamed it on plugins. To troubleshoot, I did a combo of cutting my plugin use and using a different icon library.

Anyway, I’ll get back to trying Floppy one of these days.

1 Like