Solved

toggle sort on a column title

Posted on 2006-06-21
11
360 Views
Last Modified: 2013-12-24
This query is in place for the display:

<cfquery datasource......>
      select * FROM GiftView WITH (NOLOCK)
      WHERE ConstID = #myCon#
         bla....
      Order by Created ASC, myTable
</cfquery>

The field I have:

<TD class=notetext2 width=1% nowrap align=middle>
<B><FONT color=EEEEEE>Due Date</FONT></B>
</TD>

When I click on 'Due Date', I want to have 'toggle sort' (sort by ASC or DESC back and forth), which will be basically:

Order by Created ASC

or

Order by Created DESC

I am thinking having a fucntion something like Order by Created <cfif ......>ASC <efelse> DESC</cfif>

What would be the best way to put 'toggle sort' on 'Due Date' and how to do it?
0
Comment
Question by:JohnLucania
[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
  • 4
  • 3
11 Comments
 
LVL 36

Expert Comment

by:SidFishes
ID: 16952142
you can do this with cfgrid without resubmitting the page...

or

<script type="text/javascript">
function goToURL(aURL)
            {
                  self.location = aURL;
            }


<cfparam name="url.sort" default="asc">
<TD class=notetext2 width=1% nowrap align=middle>
<B><FONT color=EEEEEE>
<cfif url.sort eq "Asc">
<input type="button" name="desc" value="Sort Desc" onClick="goToURL('thispage.cfm?sort=desc');">
<cfelse>
<input type="button" name="asc"  value="Sort Asc" onClick="goToURL('thispage.cfm?sort=asc');">
</cfif>
Due Date</FONT></B></TD>

<cfquery datasource......>
     select * FROM GiftView WITH (NOLOCK)
     WHERE ConstID = #myCon#
         bla....
     Order by Created #url.sort#, myTable
</cfquery>


you could also use an img

<img src="up_arrow.gif" alt="Sort Asc" onClick="goToURL('mypage.cfm?sort=asc');">


0
 
LVL 9

Expert Comment

by:73Spyder
ID: 16954095
Check out this script:

http://www.dhtmlgoodies.com/index.html?showDownload=true&whichScript=sortable_table

I have used it many times and it works great
0
 

Author Comment

by:JohnLucania
ID: 16985065
The issue I am having with function goToURL(aURL) is that:

The page is having the url like this:
default.cfm?fuse_action=Main&Dest=Orga&org=2094842&showType=pledgeinstallments

and the query below comes before it hits the table for display.

<cfquery datasource......>
     select * FROM GiftView WITH (NOLOCK)
     WHERE ConstID = #myCon#
         bla....
     Order by Created #url.sort#, myTable
</cfquery>

It seems that the best way is to change  "Order by Created" to ASC or DESC when the page is refreshed, so we will need to put a function to refresh the page.
For instance, if the page is clicked (in this case, refreshed), it becomes ASC; if clicked again, it becomes DESC, and so on.   I think that is the beter way.

How do you resolve this issue?



0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:JohnLucania
ID: 16985143
Actually, refreshing the page is not an issue for me since I know already.  The question I have is how to toggle ASC or DESC on the refresh.
0
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 total points
ID: 16988997
This should work
      
<script type="text/javascript">
function goToURL(aURL)
          {
               self.location = aURL;
          }



<cfquery datasource......>
     select * FROM GiftView WITH (NOLOCK)
     WHERE ConstID = #myCon#
         bla....
     Order by Created #url.sort#, myTable
</cfquery>



<cfparam name="url.sort" default="asc">
<TD class=notetext2 width=1% nowrap align=middle>
<B><FONT color=EEEEEE>
<cfif url.sort eq "Asc">
<input type="button" name="desc" value="Sort Desc" onClick="goToURL('default.cfm?fuse_action=Main&Dest=Orga&org=2094842&showType=pledgeinstallments&sort=Desc');">
<cfelse>
<input type="button" name="asc"  value="Sort Asc" onClick="goToURL('default.cfm?fuse_action=Main&Dest=Orga&org=2094842&showType=pledgeinstallments&sort=Asc');">
</cfif>
Due Date</FONT></B></TD>

0
 

Author Comment

by:JohnLucania
ID: 16989070
I have the refresh function in place.   onClick="goToURL('default.cfm?fuse_action=Main&Dest=Orga&org=2094842&showType=pledgeinstallments& .... gives more issues.   As long as I figure out how to return distinctive values (i.e. 1 or 2, yes or no, on or off, etc) whenever the page is refreshed, it sould be good to go.
For instance, the first refresh gives 1, then the next refresh gives 2, the 3rd refresh gives 1, the next gives 2, etc
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 16989108
that's "by design"


if you wish to you can eliminate the cfif

<input type="button" name="desc" value="Sort Desc" onClick="goToURL('default.cfm?fuse_action=Main&Dest=Orga&org=2094842&showType=pledgeinstallments&sort=Desc');">
<input type="button" name="asc"  value="Sort Asc" onClick="goToURL('default.cfm?fuse_action=Main&Dest=Orga&org=2094842&showType=pledgeinstallments&sort=Asc');">

this gives the user the ability to choose
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 17256519
my solution works fine for me..use it all the time
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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