Solved

Dynamic sort byclicking on column heading.

Posted on 2003-11-10
2
316 Views
Last Modified: 2013-12-24
OK, I have got this far (see code below).  What I want to do is be able to click on the column headings and have the Query add a "sort by" clause.

I assume I could do this by creating a form, then having vbscript (I don't use Javascript, hence I would use vbScript, but javascript in this exampe is completely fine) add the value to a form field, submit is and put that value in the query (or something ?? Haven't thought it out).

But... I figured there has to be an easier way?  Will Dreamweaver insert this code for you?  (I would like to know how to do it either way,)

I can write the code in .asp, but I am having a difficult time figurung this out with CF, partially because I am caching the query..

Well I think I made it clear, behind all the rambling, I just want to be ble to click on a column title and have the query sort by that value.

Thanks...  Code is below.

- I remain.

***************************************************

<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
<cfparam name="PageNum_AllListings" default="1">

<cfquery name="AllListings" datasource="Home4SaleByMe" cachedwithin = "#CreateTimeSpan(0, 6, 0, 0)#">
SELECT * FROM user975947.Listing ORDER BY Listing.Address_State
</cfquery>

<cfset MaxRows_AllListings=10>
<cfset StartRow_AllListings=Min((PageNum_AllListings-1)*MaxRows_AllListings+1,Max(AllListings.RecordCount,1))>
<cfset EndRow_AllListings=Min(StartRow_AllListings+MaxRows_AllListings-1,AllListings.RecordCount)>
<cfset TotalPages_AllListings=Ceiling(AllListings.RecordCount/MaxRows_AllListings)>
<cfset QueryString_AllListings=Iif(CGI.QUERY_STRING NEQ "",DE("&"&CGI.QUERY_STRING),DE(""))>
<cfset tempPos=ListContainsNoCase(QueryString_AllListings,"PageNum_AllListings=","&")>
<cfif tempPos NEQ 0>
  <cfset QueryString_AllListings=ListDeleteAt(QueryString_AllListings,tempPos,"&")>
</cfif>

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>Start</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</HEAD>

<BODY>
<a href="<cfoutput>#CurrentPage#?PageNum_AllListings=1#QueryString_AllListings#</cfoutput>">< First</a> |
<a href="<cfoutput>#CurrentPage#?PageNum_AllListings=#Max(DecrementValue(PageNum_AllListings),1)##QueryString_AllListings#</cfoutput>"><< Previous</a> |
<a href="<cfoutput>#CurrentPage#?PageNum_AllListings=#Min(IncrementValue(PageNum_AllListings),TotalPages_AllListings)##QueryString_AllListings#</cfoutput>">Next >></a> |
<a href="<cfoutput>#CurrentPage#?PageNum_AllListings=#TotalPages_AllListings##QueryString_AllListings#</cfoutput>">Last ></a>
&nbsp;&nbsp;Total Listings: <cfoutput>#AllListings.RecordCount#</cfoutput>

<table cellpadding="8" cellspacing="0">
      <tr bgcolor="#E8E8E8">
            <td>Listing ID</td>
            <td>First Name</td>
            <td>Last Name</td>
            <td>City</td>
            <td>State</td>
            <td>Zip</td>
      </tr>
      <cfoutput query="AllListings" startrow="#StartRow_AllListings#" maxrows="#MaxRows_AllListings#">
      <tr>
            <td>#AllListings.Listing#</td>
            <td>#AllListings.First_Name#</td>
            <td>#AllListings.Last_name#</td>
            <td>#AllListings.Address_City#</td>
            <td>#AllListings.Address_State#</td>
            <td>#AllListings.Address_Zip#</td>
      </tr>
      </cfoutput>
</table>
</BODY>
</HTML>
0
Comment
Question by:turbosig
2 Comments
 
LVL 2

Accepted Solution

by:
jonnygo55 earned 250 total points
ID: 9716890
i sometimes just use the heading names with url links...
<a href="#CurrentPage#?sortBy=first_Name>First Name</a>...

Then you could use your cached query and assuming you are using cold fusion 5 or Mx query that query like:
<cfquery datasource="query" name="allListingsSorted">
     Select * from AllListings
     Order by #url.SortBy#
</cfquery>

You'll probably also have to pass some of the other variables you are keeping track of like PageNum_AllListings

Hope that helps
0
 
LVL 2

Author Comment

by:turbosig
ID: 9718813
Thats what I thought.

Thanks.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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