Dynamic Column Sorting

sachindhus
edited February 11, 2022 in Analytics #1
Hi everyone,<br />
Here I am going to explain some points to implement dynamic column sorting in birt 4.0.<br />
<br />
1) Open report.<br />
<br />
2) Open Outline window.<br />
<br />
3) Create “SortKey” & “SortDir” report parameter.(Deselect “Is Required” & select “hidden”)<br />
<br />
4) Here we are talking about column name which is same as created in dataset. You have to expand data set to see column names.<br />
<br />
5) Select table which we are using to display result. Open property editor window . Click on General. Give any name to table it must be related to report.<br />
<br />
6) Open report click on layout which is located at bottom left side.<br />
<br />
7) Then click on Script. Select “ beforeFactory” in drop down which is at top left of the report.
table = reportContext.getDesignHandle().findElement("table");

if (params&#91;"SortDir"].value == "Desc"){
  table.getListProperty("sort").get(0).setProperty("direction","desc");
}else{
  table.getListProperty("sort").get(0).setProperty("direction","asc");
}
<br />
Note: Here table is a name of table that you have given in point 5.<br />
<br />
8) Click on header where you want to add sorting.<br />
->Property Editor ->Properties - > hyperlink-> click Edit “Link To”.<br />
Select Drill-through.<br />
Select Report Design to current report by browsing.<br />
In report parameters Click on add – Select “SortDir” past Value
if (params&#91;"SortKey"].value == "column"){
  if (params&#91;"SortDir "].value == "Asc"){
    "Desc";
  }else{
    "Asc";
  }
}else{
  "Asc";
}
<br />
Here column is same as explained in point 4. It will change for every column.<br />
<br />
9) Again add ,Select SortKey . In this case value will be name of column in “”(Double quote);<br />
<br />
10) Again add select any value from drop down. While adding value to this click on fx.->Report params -> all -> Select same parameter which we have selected in dropdown. It means we are assigning value to itself. Repeat same procedure for all parameters.<br />
<br />
Except “__htmlPagination”.<br />
<br />
11) Final Click on layout then select table . In property Editor -> Sorting -> add – Update Key to
if ( params&#91;"SortKey"].value == " columnName "){
			    row&#91;"columnName"];
}else if
<br />
12) Save report & run it.<br />
<br />
13) For next columns you have to repeat 8,9,10&11. No change in 1-7.