Solved

Coldfusion Column Sorting

Posted on 2001-09-07
2
454 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 150 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

737 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