Dynamic Column Sorting

edited November 2013 in DevShare Downloads
Hi everyone,

Here I am going to explain some points to implement dynamic column sorting in birt 4.0.



1) Open report.



2) Open Outline window.



3) Create “SortKey” & “SortDir” report parameter.(Deselect “Is Required” & select “hidden”)



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.



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.



6) Open report click on layout which is located at bottom left side.



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["SortDir"].value == "Desc"){
  table.getListProperty("sort").get(0).setProperty("direction","desc");
}else{
  table.getListProperty("sort").get(0).setProperty("direction","asc");
}


Note: Here table is a name of table that you have given in point 5.



8) Click on header where you want to add sorting.

->Property Editor ->Properties - > hyperlink-> click Edit “Link To”.

Select Drill-through.

Select Report Design to current report by browsing.

In report parameters Click on add – Select “SortDir” past Value
if (params["SortKey"].value == "column"){
  if (params["SortDir "].value == "Asc"){
    "Desc";
  }else{
    "Asc";
  }
}else{
  "Asc";
}


Here column is same as explained in point 4. It will change for every column.



9) Again add ,Select SortKey . In this case value will be name of column in “”(Double quote);



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.



Except “__htmlPagination”.



11) Final Click on layout then select table . In property Editor -> Sorting -> add – Update Key to
if ( params["SortKey"].value == " columnName "){
			    row["columnName"];
}else if


12) Save report & run it.



13) For next columns you have to repeat 8,9,10&11. No change in 1-7.
Sign In or Register to comment.