Enum status to ascending order

0
HI team, I have Status attributes with the following enum values as attached in the screenshots.I want to retrive that data on top whos status is PendingOEassignemnt if I do the sorting as asccending in retrive activity and PendingOMReview at the top when sorting Descending.I move the position of the enum value at the top but still i a not getting the desired result.
asked
3 answers
0

Hi,


This behavior is expected in Mendix and not a bug.

Mendix does not use the order of enum values defined in Studio Pro when sorting. Internally, enum attributes are stored as string keys, and any sorting (in retrieves, Data Grid 2, or lists) is performed alphabetically on those stored values.

Because of this:

  • Reordering enum values in the domain model has no impact on sorting
  • Sorting an enum attribute will always follow its internal string representation
  • Display captions are not used for sorting

Requirement Clarification

You are trying to achieve a business-defined order, for example:

  • Ascending: PendingOEassignment should appear first
  • Descending: PendingOMReview should appear first

This cannot be achieved using default enum sorting.

Introduce an explicit sort field and use that for ordering.

Step 1: Add Attribute

Add a new attribute to your entity:

  • SortOrder (Integer)

Step 2: Map Enum to Sort Order

Assign a numeric value for each enum:

  • PendingOEassignment → 1
  • Assigned → 2
  • InProgress → 3
  • Completed → 4
  • PendingOMReview → 5

This mapping can be done:

  • During create/update microflows, or
  • Using a before-commit logic

Step 3: Apply Sorting

In your retrieve or Data Grid:

  • Sort by SortOrder ASC (for ascending requirement)
  • Sort by SortOrder DESC (for reverse order)

Alternative (If Domain Model Cannot Be Changed)

Use a calculated attribute:

  • Create a calculated Integer attribute
  • Map enum values to numbers using an if-else expression
  • Sort using this calculated attribute

What Will Not Work

  • Changing enum order in Studio Pro
  • Sorting directly on enum attribute
  • Using display captions

These approaches do not affect sorting behavior in Mendix.

Mendix sorts enum attributes based on their internal string values, not the order defined in the enumeration. To achieve a custom ordering, you must implement an explicit sorting mechanism such as a numeric SortOrder attribute and use that attribute in your sorting logic.


answered
0

Hi Harsh,
Enum sorting in Mendix is:

  • String-based (alphabetical)
  • Independent of UI order
  • Not customizable without additional logic


answered
0

What you are trying to achieve is unfortunately not how Mendix handles enumeration sorting.


In Mendix, sorting an Enumeration attribute in a retrieve (ascending or descending) is not based on the order of the enum values as you arrange them in Studio Pro. So even if you move PendingOEAssignment to the top of the enum list, it will not appear first when sorting ascending.


The reason is that Mendix typically sorts enums based on their stored/technical value rather than their visual order in the model. That’s why your changes in the enum order are not reflected in the result.


If you need a specific business order (for example, always showing PendingOEAssignment first and PendingOMReviewlast), the recommended approach is to not rely on enum sorting.


Instead, add a separate Integer attribute like SortOrder to your entity and assign values based on your desired order. Then sort your retrieve using this attribute.


If you only need this in a specific case, you could also retrieve the list and apply custom sorting in a microflow or Java action, but using a dedicated sort attribute is the cleanest and most maintainable solution.


If this resolves your issue, please mark the answer as accepted.


answered