Overview

Expected Effect
When designing a report, you may hope to sort data of multiple columns in ascending/descending order by clicking the corresponding column header. For example, you hope to sort data in the first column (ID) in ascending/descending order by clicking the column header ID and sort data in the second column (Name) in ascending/descending order by clicking the column header Name, as shown in the following figure.
Implementation Method
You can add dynamic parameters in Hyperlink and add a formula in Sort After Expansion to dynamically sort data in multiple columns. That is, when you click a data column header, the cell (where the data column is located) is passed as a parameter. Then the parameter is received by the formula in Sort After Expansion to achieve different sorts based on different parameters.

1. If data to be sorted includes character-string fields, the formula in Sort After Expansion will be different. You can refer to the two examples in this document.
2. The implementation method is also applicable to dashboards.
3. If too many pages or multiple tab pages (in the Tab block of a dashboard) exist in data to be dynamically sorted, the system will refresh the page and jump to the first page after you click the column header to sort data in another page, because the dynamic parameters will refresh the entire page.
Example One
Data Preparation
Create a dataset named ds1 and enter the SQL query statement SELECT EMPID, EMPNAME, BIRTHDATE, HEIGHT FROM EMPLOYEE limit 10.
Report Design
Drag the fields EMPID, EMPNAME, BIRTHDATE, and HEIGHT into cells (from cell A3 to cell D3), enter the corresponding column headers, and set the table style, as shown in the following figure.
Dynamic Parameter Adding in Hyperlink
Select cell A2, cell C2, and cell D2 respectively, click the Hyperlink icon on the right, and add dynamic parameters. The following table describes the parameter setting of each cell.

Cell | Parameter | Value Type | Value | Description |
---|---|---|---|---|
A2 | a | Formula | if($a==-1,1,-1) | if($a==-1,1,-1) represents that the value of a is replaced every time you click the hyperlink. 1 represents the ascending order. -1 represents the descending order. The value of the parameter asc represents the cell to be sorted. Date and time data need to be set separately. |
asc | Character String | A3 | ||
C2 | a | Formula | if($a==1,-1,1) | |
asc | Character String | tointeger(format(C3,'yyyyMMddHHmmss')) Note: If time data only includes year, month, and day, the parameter will be tointeger(replace(C3,"-","")). | ||
D2 | a | Formula | if($a==1,-1,1) | |
asc | Character String | D3 |
Sort After Expansion Setting
Select cell A3, click the Cell Attribute icon, click Expansion, set Sort Basis to Formula and Sort Rule to Ascend, and enter the formula if($a==1,EVAL($asc),eval($asc)*-1).
The following table describes the formula.
Formula | Description |
---|---|
EVAL(exp) | Returns the calculated result of the expression exp. exp: a character string in the expression form. |
$asc | Returns the value of parameter $asc. |
if($a==1,eval($asc),eval($asc)*-1) | If parameter a is 1, data will be sorted in ascending order based on the value of asc. If not, data will be sorted in descending order based on the value of asc. |

Effect Display
On PC
Save the template and click Pagination Preview. The effect is shown in section "Expected Effect."
On Mobile Terminals
The template can be previewed on both the DataAnalyst and HTML5 apps. The effect is shown in the following figure.
Example Two
Character-string data cannot be sorted in example one. Therefore, you need to set date and time data separately. This example mainly introduces how to sort value, date, and character string data together.
Taking the template in example one as an example, this section introduces a different formula in Sort After Expansion.
Dynamic Parameter Adding in Hyperlink
Add dynamic parameters in Hyperlink for cell A2, cell B2, cell C2, and cell D2. The parameter setting is as follows.
Cell | Parameter | Value Type | Value | Description |
---|---|---|---|---|
A2 | a | Formula | if($a=-1,1,-1) | if($a=1,-1,1) represents that the value of a is replaced every time you click the hyperlink. 1 represents the ascending order. -1 represents the descending order. The value of the parameter asc represents the cell to be sorted. |
asc | Character String | A3 | ||
B2 | a | Formula | if($a=1,-1,1) | |
asc | Character String | B3 | ||
C2 | a | Formula | if($a=1,-1,1) | |
asc | Character String | C3 | ||
D2 | a | Formula | if($a=1,-1,1) | |
asc | Character String | D3 |
Sort After Expansion Setting
Select cell A3 and modify the formula in Sort After Expansion into INARRAY(EVAL($asc),SORTARRAY(EVAL($asc+"[!0]")))*$a.
The following table describes the formula.
Formula | Description |
---|---|
EVAL(exp) | Returns the calculated result of the expression exp. exp: a character string in the expression form. |
$asc+"[!0]" | Returns the concatenated characters. If the value of the parameter $asc is A3, A3[!0] will be returned. That is, all the values expanded from cell A3 are returned. |
SORTARRAY(array) | Returns the sorted array array. Note: If the type of array elements is inconsistent or array elements cannot be compared, the original array will be returned. |
INARRAY(co,array) | Returns the position of co in the array array, if co is not in array, 0 will be returned. |
INARRAY(EVAL($asc),SORTARRAY(EVAL($asc+"[!0]")))*$a | Sorts all the obtained values expanded from cells through SORTARRAY, returns the position of the value of the current cell in all sorted values through INARRAY, and multiplies the result (obtained from the above two formulas) by the parameter $a to sort data in ascending/descending order. |

Effect Display
On PC
Save the template and click Pagination Preview. The preview effect is shown in the following figure.
On Mobile Terminals
The template can be previewed on both the DataAnalyst and HTML5 apps. The effect is shown in the following figure.
Template Download
You can download the example templates Multi-column Dynamic Sort 1.cptMulti-column Dynamic Sort 2.cpt.