Hi Bosung Kim,
If the requirement is that users can build a cumulative sort order (e.g. Product Name → Size → Quantity), I don't believe Data Grid 2 currently supports Excel-style multi-column sorting through repeated header clicks out of the box. There is an Idea request asking for this capability.
If a default multi-column sort is sufficient, you can configure multiple sort attributes directly in the Data Grid 2 datasource settings, for example:
ProductName ASC Size ASC Quantity DESC
This works for database and XPath data sources.
For a reusable solution across different entities, I would store the user's sort preferences in a generic entity (Attribute, Direction, Sequence) and retrieve the data through a datasource microflow. This avoids creating custom logic for every grid and gives you flexibility to persist user preferences.
Store the user's selected sort criteria and drive the grid from a datasource microflow (or query layer). This keeps the implementation generic and avoids entity-specific sorting logic.
One additional consideration is user experience. If multiple sort levels are active, users should be able to see the order (for example: Product ↑ (1), Size ↑ (2), Quantity ↓ (3)) so the resulting sort remains understandable.
I hope this helps answer your question. If you need any additional details, feel free to reply below.
Best regards,
Oswaldo Valles
Hi,
For this requirement, there are two different things to distinguish: a predefined multi-column sort order and user-driven cumulative sorting.
Data Grid 2 supports sorting per column, but the standard column-header interaction does not provide a Shift-click style multi-column sort where the user can keep adding sort levels. So I would not try to work around this by creating separate microflows for every possible column combination.
If the sort order is known beforehand, you can configure multiple attributes in the Sort Order of the data source. Mendix supports multiple sort criteria, and they are applied in the order in which they are defined. For example:
ProductName ASC Size ASC Quantity DESC
This gives the expected primary → secondary → tertiary sorting behavior.
For the second requirement — where the user should dynamically build something like:
Product Name ↑ Size ↓ Quantity ↑
and keep all three levels active — the standard Data Grid 2 UI does not expose that interaction.
However, this is possible at the pluggable-widget API level. The ListValue API has a setSortOrder() method which accepts an array of SortInstructions, so multiple sort criteria can be applied at the same time. Mendix's current documentation even shows an example of sorting by two attributes simultaneously.
Conceptually, the widget can maintain something like:
[
[ProductName, "asc"],
[Size, "desc"],
[Quantity, "asc"]
]
and pass that array to:
dataSource.setSortOrder(sortInstructions)
The important part is that the attributes need to be sortable; the API exposes the sortable flag for this purpose.
For a reusable solution across different entities/grids, I would therefore avoid hard-coding entity-specific sorting logic in microflows. A custom pluggable widget can expose the grid's sortable attributes, maintain the user's sort priority/order, and call setSortOrder() with the resulting list.
One other advantage is that for Database/XPath data sources, the sorting is handled by the backend, so you are not expected to retrieve the complete dataset and sort it yourself in JavaScript.
So, in short:
ListValue.setSortOrder() is the appropriate extension point.This also keeps the sorting at the datasource level instead of implementing a client-side sort on the displayed rows, which is important when paging/large datasets are involved.
important point: setSortOrder() actually accepts multiple sort instructions.he limitation is specifically the standard DG2 user interaction, not the underlying datasource API.