Hi, I think you can use a reference selector in combination with some helper objects for this. Double click on the reference selector, go to tab selectable objects and choose the microflow option as a source.
Also create a helper object which also includes the name caption of the enumeration and associate this object with your 'main' object which you are displaying on the page.
You can now retrieve the helper objects in your selectable objects source microflow and sort them here.
Hi Selwyn,
You are correct that changing the enumeration keys to include alphabetical prefixes is not a good long-term solution.
Mendix does not provide a direct runtime sorting option to sort an enumeration dropdown by its translated caption. A better approach is to use a helper entity with a Reference Selector.
1. Create a helper entity
For example, create a non-persistent entity called EnumOption with these attributes:
EnumKey – String
DisplayName – String
You can also use an enumeration attribute in the helper entity if you want to retain the original enum value.
2. Create a data source microflow
Create a microflow that:
Retrieves or creates the helper objects for all enumeration values.
Assigns the appropriate display caption using getCaption().
Returns the helper objects sorted by DisplayName ascending.
For example:
EnumKey DisplayName
Active Active
Completed Completed
InProgress In Progress
Pending Pending3. Configure a Reference Selector
On your page:
Use the helper entity as the selectable objects source.
Configure the source as a microflow.
Set the caption to DisplayName.
Configure sorting by DisplayName ascending.
4. Update the original enumeration attribute
When the user selects a helper object, use an On Change microflow to map its EnumKey back to the corresponding enumeration value and update the original entity's enumeration attribute.
For example:
If $EnumOption/EnumKey = 'Active'
Set Status = Module.Status.Active
If $EnumOption/EnumKey = 'Completed'
Set Status = Module.Status.CompletedMake sure to handle empty selections and all possible enum values.
If you only need a fixed order and do not need dynamic sorting based on translations, you can manually arrange the enumeration values in Studio Pro in the desired order. However, this is not the same as dynamically sorting by caption.
My recommendation: Use the helper entity approach if the captions must be sorted alphabetically, especially when the application supports multiple languages. It keeps the original enumeration keys unchanged and avoids dummy prefixes or database-wide migration.
References:
Hope this helps! If you find this answer helpful, please mark it as the accepted answer.
Hi Selwyn,
One possible workaround is to use a helper entity with a String attribute to store the enumeration captions. You can populate this attribute with the corresponding caption values and use it for alphabetical sorting in the dropdown.
This avoids modifying the existing enumeration keys or migrating your current entity data. It may require some additional logic to maintain the helper records, but it keeps the existing data structure intact.
Hope this helps!
You can try using Combo box with below settings and mention the sort order in enumeration where it is defined.