Overview
Application Scenario
You can sort data (in ascending/descending order) in a column by clicking the column header (obtained by the horizontal expansion of a field) when previewing a report, as shown in the following figure.
Implementation Method
You can obtain all values of the clicked column and set Sort After Expansion in Cell Attribute of the cell where the field Sales Person is located, to sort sales persons based on all values of the clicked column.
Example
Data Preparation
1. Create a general report, create a database query named ds1, and enter the SQL statement SELECT * FROM Sales_Volume.
Report Design
The following figure shows the designed table style.
The following table shows the cell attribute setting.
Cell | Dataset | Data Column | Attribute |
---|---|---|---|
A2 | ds1 | Sales Person | Set Expansion Direction to Vertical and center the data column. (Retain default setting for other attributes.) |
B1 | ds1 | Product | Set Expansion Direction to Horizontal and center the data column. (Retain default setting for other attributes.) |
B2 | ds1 | Sales Volume | Set Expansion Direction to No Expansion and Data Setting to Summary and Sum, and center the data column. (Retain default setting for other attributes.) |
Dynamic Parameter Adding
Add a hyperlink (dynamic parameter type) to cell B1 and rename the hyperlink to Sort.
Add two parameters order (value formula: if($order = 1, -1, 1)) and index (value formula: &B1), as shown in the following figure.
Sort After Expansion Setting
Select cell A2, click the Cell Attribute icon on the attribute panel, click Expansion, set Sort Rule in Sort After Expansion to Ascend, and enter the formula if(isnull($index), A2, if($order = 1, EVAL("B2[;B1:" + $index + "]"), EVAL("-1*B2[;B1:" + $index + "]"))).
When order is 1, the values of the clicked column obtained by EVAL("B2[;B1:" + $index + "]") are sorted in ascending order. When order is -1, the values of the clicked column are first converted to negative numbers and then sorted in ascending order based on the negative numbers.
The following table describes the formula.
Effect Display
On PC
Save the template and click Pagination Preview. The following figure shows the sort effect.
On Mobile Terminals
The preview effects on the DataAnalyst and HTML5 apps are the same, as shown in the following figure.
Template Download
You can download the example template Multi-column Sort of Horizontally Expanded Columns.cpt.