re-order table generated by coldfusion by clicking on header

Posted on 2003-03-27
Medium Priority
Last Modified: 2013-12-24
I have a simple cfm page.  I am generating a table from a database and would like to be able to re-order the table according to the different headers in it.  The page is at http://saugus.byu.edu/gened/alcuin.cfm

Here is the code I am using to order the page now:
<cfquery name= "AlcuinQuery" datasource= "awards">
     SELECT * FROM AlcuinRecipient ORDER BY "ID" DESC

I would like to be able to let the user click on the header to sort either ascending or descending by year, name, position, or department.  I could do it fairly easily by creating different pages that linked to the header, but I would like to do it all in one page.

In other words, if you click on year then the page will be sorted by year (descending).  If you click on year again it will re-sort the page and make the years ascending.  If you click on name it will order the table according to name...etc.

Please let me know any suggestions you have (and if this makes sense).
Question by:bobwils
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8220421
<cfparam name="url.orderBy" default="ID">

<cfquery name= "AlcuinQuery" datasource= "awards">
    SELECT *
    FROM AlcuinRecipient
    ORDER BY #url.orderBy# DESC

Then the links for the headers would do this:

<a href="alcuin.cfm?orderBy=year">Year</a>

Expert Comment

ID: 8222584
above comments will solve your problem
LVL 17

Accepted Solution

anandkp earned 200 total points
ID: 8222680
a small addition to the above suggestion

<cfparam name="orderBy" default="ID">
<cfparam name="AscDesc" default="Asc">

<cfquery name= "AlcuinQuery" datasource= "awards">
   SELECT * FROM AlcuinRecipient
   ORDER BY #orderBy# #AscDesc#

Then the links for the headers would do this:

<CFIF AscDesc EQ 'Asc'>
   <a href="alcuin.cfm?orderBy=year&AscDesc=Desc">Year in Desc order</a>
   <a href="alcuin.cfm?orderBy=year&AscDesc=Asc">Year in Asc Order</a>

since u asked for both ascending & descending options !


Author Comment

ID: 8225669
Although the earlier comments worked, I wanted to do it in both ascending and descending order.  This answer worked wonderfully!  Thanks so much.

Expert Comment

ID: 8225693
Oops, I missed that part. Good catch Anand.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question