1. Aggregate and Grouping:
Our aggregate (GetLearningInstances) queries multiple entities with joins and uses Group By clauses along with a calculated aggregation (Count(Document.Id) aliased as DocCount) to present aggregated rows in a table widget.
2. Aliases Passed as Input for Dynamic Sorting:
Because the aggregate contains Group By projections, the original entity attributes are transformed into alias names (e.g., LearningInstanceName, LearningInstanceModifiedDate, DocCount). These alias strings are passed from the UI column headers into the dynamic sort parameter (TableSort).
3. Dynamic Sort with Current Sorting Logic:
We configured a single Dynamic Sort entry (TableSort) in the Aggregate's Sorting tab. In the client-side OnSort action, clicking a column toggles TableSort between "AliasName" and "AliasName DESC", resets StartIndex = 0, and executes a Refresh Data node.
4. Default Sorting in Descending Order:
The screen variable TableSort is initialized with a default value of "LearningInstanceModifiedDate DESC" so that the newest modified records appear first on screen load.**The Issue / Current Behavior**Despite TableSort updating dynamically at runtime (e.g., changing from "LearningInstanceModifiedDate DESC" to "LearningInstanceName DESC" or "DocCount"), the aggregate completely ignores the dynamic sort expression. Please advise on how to achieve runtime dynamic sorting over grouped aggregates containing count calculations without being forced to rewrite the aggregate into a custom SQL tool. Went through the following recommendations still does not work. https://www.outsystems.com/forums/discussion/19105/sorting-on-an-aggregate-with-a-group-by/https://www.outsystems.com/forums/discussion/91820/how-to-sort-on-group-by-values-in-aggregate-reactive/
Hello.
The rules is Entity names between [], Entity Attributes between {} and Calculated Attributes as plain text. Seems ok.
Usually the problem is that your dynamic sort is only the second condition. Can Date be different for all records and that's why the second sorting is ignored?
Hi Nuno, Thanks for reviewing. I changed the ordering of the sorting and also updated the logic for it and now it is working. The date remains the same for all records.
Hi Yash,
Like Nuno said, you are first sorting on LearningInstanceModifedDate, regardless of the dynamic sort. So when you are "changing from "LearningInstanceModifiedDate DESC" to "LearningInstanceName DESC" or "DocCount"" you are really changing from LearningInstancemodifiedDate DESC (from the non-dynamic sorting) to LearningInstancemodifiedDate DESC then sort on LearningInstanceName DESC. You should remove that first sort and only have the dynamic one.
Hi Killian, Thanks for the solution