On startup of the report processing, pre-process the report's main data-set so that it is sorted according to a sort-key. This sorting is controlled by an attribute on the master-report, which defaults to "sort" for all new reports, and to "dont-sort" for all existing/legacy reports.
The sort-key is auto-computed based on the groups defined on the report. Each group will receive a new attribute to determine the sort order (Ascending/Descending), which defaults to Ascending.
Sorting of data-sets is a mandatory prerequisite for crosstab editing, but has general use outside of crosstabs.