<a href= "Javascript:setorder ();" > Header name </a>, the page gets the name of the last-clicked header and the name of the header you clicked, and if the same is the same as in the original reverse order, otherwise the new column is ascending,
Get the column name and order of the order, upload to the background to get the corresponding SQL, add the order BY statement, complete the sorting function
The sort order value can be stored in the form in a hidden field, as is the idea.
For example, when you use the Birt Report tool to create a report by clicking on the name of the header, you can add a hyperlink to the header name, link to the targeturl+ header name, and then in the initialization method initialize () To determine whether the original header name is the same as the incoming header name to determine ascending and descending order, then get SQL, add a sort statement, and complete the function. Here is an example of the report I made.
Copy Code code as follows:
DatasetName = "Fundcatagoryseasontemplate";
Sortcol = Reportcontext.gethttpservletrequest (). GetParameter ("Sortcol"); Get the column name you want to sort
Sortdir = Reportcontext.gethttpservletrequest (). GetParameter ("Sortdir");//Get Arrange Order
Currenturl = Reportcontext.gethttpservletrequest (). Getrequesturl () + "?" +reportcontext.gethttpservletrequest (). getquerystring ();
Sortclause = "";
TargetUrl = "";
if (Sortdir!= null) {
if (Sortdir.indexof ("ASC")!=-1) {
Sortdir = "DESC";
}else{
Sortdir = "ASC";
}
}else{
Sortdir = "ASC";
}
if (sortcol!= null && sortcol.length!= 0) {
Sortclause = "ORDER BY" + Sortcol + "" + sortdir;
}
Reportcontext.getreportrunnable (). Getdesigninstance (). GetDataSet (DatasetName). QueryText + = SortClause; Get and modify the underlying SQL statement
if (Currenturl.indexof ("__sorting=")!=-1) {
TargetUrl = currenturl.substring (0,currenturl.indexof ("__sorting")-1);
}else{
TargetUrl = Currenturl;
}
TargetUrl = TargetUrl + "&__sorting=true&sortdir=" +sortdir+ "&sortcol=";//Modify URL