Forum Academy Marketplace Showcase Pricing Features

Recalculate the number order in a list

Hello,

I’m relatively new with Bubble, and I’m not sure if I’m using the correct terms when explaining what I’m trying to solve.

I found this old thread that was really close to a solution, but I didn’t fully understand how to implement it.

I’ve created an illustration that may communicate my situation probably better than I can describe the problem and workflow needs. See image below.

Problem to Solve:
Trying to find a way that allows a list to be dynamic (add and delete records) and then displays the count of records within a dropdown menu. This dropdown menu reflects the Sorting Order for the category list items. The lower the number a category is assigned from the dropdown menu the higher the descending position. Using this dropdown menu, the user can change the category vertical position instantly.

Please Note:

  • The categories are being created dynamically by the user already.
  • The Categories are within a Repeating Group.

When ONE dropdown changes ALL the other dropdowns will adjust their list accordingly. The dropdown list is based on the number of categories in total at that time (added or deleted) the user has created, so the Sort Order List (represented by the Dropdown Menu) will need be dynamic. N0 more than 8 categories in total will be listed, pending how may the user create (8 is the limit).

IF you see a better way to sort the dynamic choices for the user then previous described or communicated in the illustration while still including the needs I’m trying to describe I’m open to your advice : )

I appreciate any help you can provide. Thanks!

Luckily RGs are dynamic - in the sense that they will update themselves in realtime in response to a change in their DB values.

So, I would suggest creating a field under the type of things in the RG called ‘position’. Once you have this, you can set the RG’s data as ‘your list of things: sorted by position’.

Now the RG will auto-update whenever the position values are changed. And if the position values are not set, it will order by the default ‘date Created’ value.

Now in your dropdown, we’ll have to assign a list of numbers that ends with the number of items in the RG. If this is dynamic, you can use the Toolbox Plugin’s List of Numbers functionality.
Once you install the Toolbox Plugin, you’ll see a ‘List of Numbers’ element under your available elements on the left panel. Add one of those into the RG, so that each item in the RG has one. Then set it up to have a list of numbers starting from 1 and ending at ‘Repeating Group X’s list of things: count’

Now go to the workflows and create a new workflow that executes when an input element is changed.
Select this input element as the dropdown inside the RG and in the workflow add an action to change a thing → select the current Cell’s thing and update the position there. In the same workflow you can also update the position of the other items in the list. One way could be to set the old position of this modified cell to the position of the cell that currently holds that position.

Cheers,
Ranjit | Blur Apps

Hi Ranjit,

Your help is greatly appreciated! Seems relatively straight forward, however, after reading through you explanation dissecting the information, I still require a little more help. You see, my skills with the Property Editor are not that strong yet and making the proper data connections is where I’m having trouble.

Once I can connect things correctly, I’m sure the Workflows will fall into place.

Quick Notes:

  • Toolbox plugin is installed.
  • Datatype = Menu Items CatGrp
  • Field “Position” created within Datatype Menu Items CatGrp (should field be a number or list of numbers?) Not clear how this is storing the numbers?
  • Repeating Group = RG Menu Item CatGrp
  • Group Header Accordion is nested inside of RG Menu Item CatGrp
  • List of Numbers is within the RG Menu Item CatGrp
  • Dropdown is within the Group Header Accordion

If you could let me know the missing details to the Property Editor I’m missing I would appreciate it. Please review images.

  1. RG Menu Item CatGrp
  2. Dropdown
  3. List of Numbers (not clear how to drill down to the data to find the correct solution. Each expression seems to result in RED lettering.)
  • Start number, I’m guessing, but is this the RG first cell’s number?
  • Length Number, again I’m guessing, but shouldn’t this be the total number of Menu Item CatGrp counted within the RG?
  • Increments, it’s one number, right? How to tell Bubble this I’m not clear one.

Hi @thinkjon

ListOfNumbers:

  • this should be within the RG - so that it repeats on each cell (I think that’s what you’ve done already)
  • Start Number is 1 - you can just type ‘1’ into that field (because our positions will always start with position 1)
  • Increment is 1 - again just type it there
  • Length of List is RG Menu Item CatGrp's list of things :count

Within CatGrp Data Type, the ‘position’ field should be of type ‘number’ (not a list). This is because we want to associate a single position value with each entry of this data type.

Dropdown:

  • In the Dropdown (Sort CatGrp), the type of choices is number
  • Choices source is List of Numbers B's List

Repeating Group:

  • Data Source: search for Menu Item CatGrps -> Sort by: *Position* & Descending: *"no"
  • Layout Style: Full list
    (this can be changed as per your UI requirements. For now this will help use make sure all the items are listed correctly)

Once you’re here, you can set up the workflows that trigger ‘when an input is changed’ as I mentioned in my first answer.

Let me know how it goes!
Ranjit

Hi Ranjit,

Thanks for your time and reply. I followed all your notes to each section (ListOfNumbers, Dropdown, Repeating Group). Unfortunately, it’s not working yet - review Property Editor and Workflows screen captures below.

Dropdown:

  • No numbers are being stored within the database, therefore the dropdown is blank.

Workflows:

  • Am I selecting the correct thing to change?
  • The “position” field, how does it get its data for the record? It’s the plugin, correct? But where do I tell the plugin to find the"position" field?

Any feedback you can provide is greatly appreciated. Thanks - Jon