How can I use a parameter for sorting a datadefinition?

Hello!

The goal is to sort a list based on a parameter, either ascending or descending.

For example %sorting: “this.createdat.asc”

In the datadefinition in the sort field, it does not accept my parameter of type string.
It only accepts it if I use %sorting.asc.
This however forces me to alwas sort ascending.

Is it possible to use the parameter in a way I can define asc/desc myself? Or is there an alternative that is better suited for this usecase?

Hi Yori,
See M8737 → Sort expression validated expression field.
It is configured for return types OrderBy.
However, AFAIK you cannot create an expression that evaluates to an orderby datatype (I don’t even see it in the datamodel)

This is one of the reasons that for the REST Data definitions sort expression uses list string as a return type, instead of orderby - so you can dynamically set the sorting type.

So, if you are to use this sorting in the REST context, simply configure your sorting on REST Data definition level, instead of Data definition, and what you ask is possible - you can provide entire parameter in the query like “id.asc” or “yori.desc”. Then the sort expr config would be [%my_sort_param_name] - and of course the REST data definition parameter with name my_sort_param_name is of datatype string.

If its for something else, becomes a bit harder. Technically, it might be possible to change the configuration of the Sort expression on the Data definition record, to be of return types List.
But that has its risks as well:

  • Not sure what will happen with all existing expression, probably all of the would need to be fixed…
  • Not sure if that can be quickfixed

Greetings,
Miroslav

1 Like

Thanks Miroslav for your reply, I’ll have a look if I can manage it on REST data definition :wink: