Get the name of the last-clicked header and the name of the header you clicked, and if the two are the same, arrange in the reverse order, or the new column ascending
<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 ascending order, get the column name and order of the Order, Upload to the background to get the appropriate SQL, add an order BY statement, complete the sorting function Sort sequence values can be stored in the form in the hidden field, the idea is this. 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, the link content to the targeturl+ header name, and then 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 to be sorted Sortdir = Reportcontext.gethttpservletrequest (). GetParameter ("Sortdir")//Get order Currenturl = Reportcontext.gethttpservletrequest (). Getrequesturl () + "?" +reportcontext.gethttpservletrequest (). GetQueryString (); sortclause = ""; TargetUrl = ""; if (sortdir!= null) { if (sortdir.indexof ("ASC")!=-1) { Sortdir = "DESC"; }else{ -sortdir = "ASC"; } }else{ = "ASC"; sortdir Sp } if (sortcol!= null && sortcol.length!= 0) { Sortclause = "ORDER BY" + Sortcol + "" + Sort dir; } reportcontext.getreportrunnable (). Getdesigninstance (). GetDataSet (dataSetName). QueryText + + Sortclause; Gets and modifies 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