I'm trying to do the same but with GroupBy on the aggregate.
I tried with calculated attributes and it's fine but if i try to order by an attribute from the GroupBy it doesn't work.
Ps: i'm using p10
Mikael Serra wrote:
Have the same request :)
Does not want to sort by my Group By column
Since various sorting options have been discussed here, could you detail what kind of sorting you are looking for?
Kilian Hekhuis wrote:
Sorting on a Group By column.
The group by column name is "FirstName" so made my dynamic search as follows:
SyntaxEditor Code Snippet
and on the table List_SortColumn "FirstName" but not sorting in the preparation or on the click of the column name.
Thank you :)
Since I'm still not entirely sure what your functional requirements are, I'll explain the two methods of sorting on a calculated or grouped column.
First, the static way, is to add a Sort directly to the aggregate. In the aggregate, click the Sorting tab, and click "Add Sort". In the "Select Attribute" pop-up, select one of the calculated or grouped columns (shown at the top, indicated by a green, instead of a blue, attribute icon). Use this method if you only ever want a single way of sorting.
Secondly, the dynamic way, using the RichWidgets List_SortColumn_GetOrderBy and List_SortColumn_SetOrderBy actions. Both actions have, as their first parameter, the widget Id of the Table Records you plan to use the output of the query in. Note that you could as well use any other unique identifier if you don't have a Table Records widget associated with the query, as long as the Id you use for the List_SortColumn_GetOrderBy is the same as the Id you use for the List_SortColumn_SetOrderBy (I assume RichWidgets uses a session variable to store the orders). In the aggregate, click the Sorting tab, and click "Add Dynamic Sort". In the expression editor that opens, enter List_SortColumn_GetOrderBy(myId), where myId is the Id I explained above (typically TableRecords.Id). By default, GetOrderBy returns an empty string, so your query is unsorted. To sort, use SetOrderBy, specifying the Id, the column name (this is the name you gave your calculated or grouped column), and optionally the direction of sorting ("ASC" or "DESC"). Where in the code you use the SetOrderBy is up to you. You could use the RichWidget's List_SortColumn widget, that presumably implicitly also uses List_SortColumn_SetOrderBy. Or you could create a widget yourself.
I hope this explains it all, if not feel free to ask.
Mariaan Bosman wrote:
If you're having problems with the richwidget dynamic sort you could always use SortRecordList http://www.outsystems.com/forge/component/22/sortrecordlist/ and create your own ajax refresh action to sort using SortRecordList (This could also be done in the prep as well.)
In general, it's unwise to move on to different measures if something doesn't work, and you don't know why. Understanding why something doesn't work is very important. Giving up and using something that's not specifically suited for the task is bad advice, imho.
Secondly, starting with version 10 I'd use the built-in ListSort instead of SortRecordList, unless you want to sort on multiple columns at the same time. But again, I wouldn't go around sorting lists in memory unless you have a very specific use-case for it.
Thank you Killian
If you mean "thanks for the effort, but it's still not what I want" than I'd like to know if I can assist any further :).
If you mean "thanks that solved it for me", I'd want to ask you to mark my answer as the solution (and Like it :)) so the topic is marked as solved.
Why not use an advanced query?
Rui Barbosa wrote:
Yes I can. I actually had it like that originally, but then I need to maintain a structure with it and instead of just adding a new group by field if I want to add a new column.
I would think it would just be simple to add the column name as the sort by field.
For now I have just sorted it by the FirstName column. Will change it to use a structure instead.