Show selected combo box items first in list

0
Hey all,I was wondering if there is a possibility to display the selected items in a combo box on top, before the unselected items. I don't see a setting for this inside of the widget propertiesCurrently our implementation looks like this:And we wanted it to show both selected items on top, like this:Has anyone done this already?ThanksLenny
asked
3 answers
0

This is not controlled by the Combo Box widget directly. The widget will display the items based on the sorting order coming from the datasource.

A common approach is to prepare the datasource with a custom sort order.

For example, create a helper attribute: SortOrder

Then when loading the list:

  • Selected items → SortOrder = 1
  • Unselected items → SortOrder = 2

Then configure the datasource sorting:

SortOrder = Ascending
Country Name = Ascending

The result will be:

✓ Algeria
✓ Benin
□ Angola
□ Botswana
□ Cameroon
...

The important part is that the Combo Box does not reorder association values automatically based on selection state, so the ordering logic needs to happen in the datasource/microflow.

Kindly mark this as the accepted answer if it helps.

answered
0

I've put together an example here using the Atlas template.


The goal is to create an association between Entity (I left it with this name to be generic. It could be Account or another entity) and AtlasCountry, but ordering the selected items to the top of the list.


First, you have to use a DataView of the Entity. Here we can pass it as page context, but for didactic purposes, I created a Microflow DS_Entity.




DataView settings we will have a microflow DS_AtlasCountry_Sorted to retrieve the AtlasCountries. Note the association in blue.



The DS_AtlasCountry_Sorted microflow will have a trick:

  1. Retrieve by association to get the Countries from the Entity, which I called CountryList_Selected;
  2. Retrieve all the Countries from the database, using Sorting by Name, which I called CountryList_SortByName;
  3. Subtract CountryList_Seleted from CountryList_SortByName. This will create a new list, which I called CountryList_Substract;
  4. Sort by name using CountryList_Selected. This will create a new list, which I called CountryList_Return, which will be the return of the flow;
  5. Add the CountryList_Substract list to CountryList_Return.




With this, you will have the selected values ​​at the top of the list and then the rest of the database.



Now the biggest trick is to make this microflow be called every time a value is selected. This is simple. In the Events tab of the combo box, select the On change action option to call a nanoflow (it has to be a nanoflow) that will be called every time there are changes in the combo box.


This nanoflow will simply refresh the Entity. This forces the combo box widget to be rendered every time there are changes. This in turn will call the DS_AtlasCountry_Sorted microflow.






The results:



answered
0

Lenny,

I created a small example.


Here is my domain model:


I thne created a page to populate both Product and Country entities.


The Product_NewEdit page looks like this:


The Combo Box uses a Datasource Microflow that looks like this:


The Combo Box is Events tab looks like this:


This works as you described. You may want to change the Combo Box Events tab so that it does not save changes when you select countries. You should see how you want this to behave.


Hope that helps,

Mike


answered