Introduction to the function example of sorting by clicking on the header in table

Source: Internet
Author: User
Tags sort

  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&gt, 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   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.