SAPUI5 1.56: Improved Grouping and Sorting in Analytical Tables
Analytical Tables display aggregated data using special analytical OData V2 services. The aggregated data can be grouped to make analysis easier. Within the grouped data, it is possible to drill-down for a specific combination of dimensions. This is shown in Figure 1 below. In this example, the data is grouped by Customer Country and Product Category. The additional dimension Product is available only on leaf level. The displayed measure is Total Net Amount.
Up to SAPUI5 version 1.54, the data was sorted by the dimensions that are used for grouping. Sorting by further fields, in particular sorting by aggregated amount or quantity fields, was possible but took effect only on leaf level. The sort order imposed by the grouping dimensions was preventing another sort order for the group levels.
As of SAPUI5 version 1.56, this is changed automatically if certain preconditions are fulfilled. Figure 2 shows how sorting by Total Net Amount has also changed the order of the group levels. The country with the biggest sales volume is now shown first.
The following preconditions must be met to enable sorting on group levels:
- Multiple units must not occur in the displayed data. The occurrence of multiple units is indicated either by a link to details or by a * instead of the unit/currency in the Unit/Currency column. This condition is checked against the grand total. Note that the grand total may not be displayed but is still used for this check.
The occurrence of multiple units can be influenced by filters and the field selection. I.e., the sorting on group levels may work or not depending on the fields selected and filters provided by the user.
- The autoExpandMode of the AnalyticalBinding has to be set to Sequential. Note that the default is Bundled.
This is a technical setting that needs to be set by application developer. Changing this setting will have an effect when the automatic expansion of group levels is performed. The autoExpandMode Sequential will mimic the manual expansion of the user and is typically running significantly slower than the default mode Bundled.
An optimistic approach is used if the grand total is not yet available on the client when requesting to sort by other fields than the grouping dimensions. It is assumed that the new sort behavior can be used. The grand total is requested in parallel with the data within the same batch request. Once the grand total is available, it can be checked whether multiple units occur within the displayed data. If this is the case, it is necessary to switch back to the old sort order by the grouping dimensions and request the data anew. The advantage of the optimistic approach is that only one batch request is required if multiple units within one column do not occur.
Thank you, Mathias. Any code sample would be helpful.
-- Seyed Ismail
there is little code required. The example above was created with the following binding.
The important part is to set the autoExpandMode as described in the blog post. The new sort behavior will then be used whenever there is no multi-unit situation present.
Thanks so much for your sharing, it saved me a lot of time to debug the source code of UI5😄