Table to click on the list to implement the sorting function example Introduction _jsp programming

Source: Internet
Author: User

<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

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.