?
Solved

Coldfusion Column Sorting

Posted on 2001-09-07
2
Medium Priority
?
470 Views
Last Modified: 2013-12-20
I want to know how to sort the columns of a query.  I know how to do it via the SQL statement.  What I need is for a user to be able to pull up the webpage with query and click on the column headings of the table to sort it by that column(asc AND desc would be great...).  For example...  Lets say I have a table called "music", and I have fields: ID, Artist, Title, Description, and etc.  I want the user to be able to click on ID to sort the table by ID and if they click on Artist, sort by artist, and etc.  If there is anyone who can help me on this, it would be greatly appreciated.
0
Comment
Question by:bptacek
[X]
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
2 Comments
 
LVL 1

Accepted Solution

by:
snakehollywood earned 600 total points
ID: 6464528
Put buttons into your table headers that will act as the sort button.
When the button is clicked on, it will pass the name of the column to sort into a hidden form field, and then submit the form back to the same page.

e.g

<td><input type="submit" name="sortorder" value="Name" onclick="document.forms[0].orderby.value='name ASC'"></td>

this puts a button into your column header, which when clicke don, will pass the value "name ASC" into the hidden form field called orderby.

At the top of the page you simply check for the existance of the form button, if it exists then apply a dynamic where clause using the hidden formfield.

e.g

<cfquery>
select * from table
<cfif isdefined('form.sortorder')>
order by #form.orderby#
</cfif>
</cfquery>

this will order your query by the column "name" in ascending order.

Now you just create buttons for each column you wish to sort. You can use image buttons for ASC and DESC options.

0
 

Author Comment

by:bptacek
ID: 6464741
Thanks snakehollywood, that makes sense.  Thanks again!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses

743 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