In table click on the header to implement the sorting function

  • 2020-10-23 20:15:35
  • OfStack

< a href="javascript:setOrder();" > Header name < /a > , get the name of the header of the last click and compare it with the name of the header of this click. If the two are the same, they will be arranged in reverse order. Otherwise, the new column will be arranged in ascending order.

After obtaining the column name and ordering of the sorting order, send it to the background to get the corresponding sql, and add order by statement to complete the sorting function

Sort order values can be stored in hidden fields in form, and that's the idea.

For example in the use of Birt report tool to create report have to click on the name of the header sort function, can increase a hyperlink, header name place again for link content TargetURL + name of the header, and then the initialization method initialize () determine whether the original header name is the same as the incoming header name to determine ascending and descending, and then obtain sql, add sorting statements, complete functions. Here is an example of the report I did.

 
dataSetName = "fundcatagoryseasontemplate"; 
sortCol = reportContext.getHttpServletRequest().getParameter("sortCol");// Gets the name of the column you want to sort  
sortDir = reportContext.getHttpServletRequest().getParameter("sortDir");// Get permutation 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 &amp;&amp; sortCol.length != 0){ 
sortClause = " order by " + sortCol + " " + sortDir; 
} 

reportContext.getReportRunnable().getDesignInstance().getDataSet(dataSetName).queryText += sortClause; // Get and modify the underlying layer sql statements  

if(currentURL.indexOf("__sorting=") != -1 ){ 
targetURL = currentURL.substring(0,currentURL.indexOf("__sorting")-1 ); 
}else{ 
targetURL = currentURL; 
} 

targetURL = targetURL + "&amp;__sorting=true&amp;sortDir="+sortDir+"&amp;sortCol=";// Modify the url 


Related articles: