943,865 Members | Top Members by Rank

Ad:
  • ColdFusion Discussion Thread
  • Marked Solved
  • Views: 2947
  • ColdFusion RSS
Jul 14th, 2008
0

navigation button

Expand Post »
have anyone ever creates navigation buttons such as next,previous in coldfusion?

can i see ours if you have created one?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
nish88 is offline Offline
46 posts
since Nov 2007
Jul 14th, 2008
0

Re: navigation button

Based on query data? If so yes, but I don't have it with me at the moment. I'll get back to you.
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008
Jul 15th, 2008
0

Re: navigation button

ya its based on query.
so thanks in advance..
Reputation Points: 10
Solved Threads: 0
Light Poster
nish88 is offline Offline
46 posts
since Nov 2007
Jul 15th, 2008
0

Re: navigation button

Are you permitted by your hosting company to use custom tags?
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008
Jul 16th, 2008
0

Re: navigation button

ya am permitted
Reputation Points: 10
Solved Threads: 0
Light Poster
nish88 is offline Offline
46 posts
since Nov 2007
Jul 16th, 2008
0

Re: navigation button

OK. I have a custom tag that will pretty much do everything for you. I'll post it in the morning when I get back to work.
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008
Jul 16th, 2008
0

Re: navigation button

Here goes. There's a lot here, so bear with me. This is actually two custom tags. One to set the variables and one to create the links.

Here is the first custom tag:

ColdFusion Syntax (Toggle Plain Text)
  1. <!--- pageNumSetup.cfm --->
  2.  
  3. <cfscript>
  4. // round page number variable up
  5. function roundPageNum(number) {
  6.  
  7. var x = 0;
  8.  
  9. x = Int(number);
  10.  
  11. if(number - x neq 0) {
  12. x = x + 1;
  13. }
  14.  
  15. return x;
  16. }
  17. </cfscript>
  18.  
  19. <!--- Set Default values --->
  20. <cfparam name="Caller.startRow" default="1">
  21. <cfparam name="Caller.nextPage" default="">
  22. <cfparam name="Caller.prevPage" default="">
  23. <cfparam name="Caller.numPerPage" default="20">
  24. <cfparam name="Caller.numPages" default="0">
  25. <cfparam name="Caller.curPage" default="1">
  26. <cfparam name="Attributes.queryName" default="">
  27.  
  28. <!--- Set values for previous and next pages --->
  29. <cfset Caller.nextPage = Caller.startRow + Caller.numPerPage>
  30. <cfset Caller.prevPage = Caller.startRow - Caller.numPerPage>
  31.  
  32. <!--- Determine the total number of pages for this search --->
  33. <cfset Caller.numPages = Attributes.queryName.RecordCount / Caller.numPerPage >
  34. <cfset Caller.numPages = roundPageNum(Caller.numPages)>
  35. <cfset Caller.curPage = ((Caller.startrow -1) / Caller.numPerPage) + 1>

Now for the navigation links:

ColdFusion Syntax (Toggle Plain Text)
  1. <!--- pageNum.cfm --->
  2.  
  3. <!--- Set Default values --->
  4. <cfparam name="Caller.startRow" default=""> <!--- Numeric --->
  5. <cfparam name="Caller.nextPage" default=""> <!--- Numeric --->
  6. <cfparam name="Caller.prevPage" default=""> <!--- Numeric --->
  7. <cfparam name="Caller.numPerPage" default="20"> <!--- Numeric --->
  8. <cfparam name="Caller.numPages" default=""> <!--- Numeric --->
  9. <cfparam name="Caller.curPage" default=""> <!--- Numeric --->
  10. <cfparam name="Caller.queryName" default=""> <!--- Query --->
  11. <cfparam name="Attributes.forwardImage" default=""> <!--- string --->
  12. <cfparam name="Attributes.backImage" default=""> <!--- string --->
  13.  
  14. <!--- This variable is used to direct the links to the correct template --->
  15. <cfparam name="Attributes.pageName" default="Index.cfm"> <!--- string --->
  16.  
  17. <!--- If there is only one page of results, there is no need to show links --->
  18. <cfif Attributes.queryName.RecordCount LT Attributes.numPerPage>
  19. <span class="curPage">Page 1 of 1</span>
  20. <cfelse>
  21.  
  22. <cfoutput>
  23.  
  24. <!--- If this is not the first page, show a link to the previous --->
  25. <cfif Attributes.prevPage gt 0>
  26. <a href="#Attributes.pageName#?startrow=#Attributes.prevPage#" class="pageNum"><cfif Attributes.backImage neq ""><img src="#Attributes.backImage#" border="0" /><cfelse>&lt;&lt;Previous Page</cfif></a>&nbsp;&nbsp;
  27. </cfif>
  28.  
  29. <!--- If this is the first page, show the page number without a link --->
  30. <cfif Attributes.curPage eq 1>
  31. <span class="curPage">1</span>
  32. <cfelse>
  33. <a href="#Attributes.pageName#?startRow=1" class="pageNum">1</a>
  34. </cfif>
  35.  
  36. <!--- Loop through the number of pages and create the links --->
  37. <cfloop index="LoopCount" from="2" to="#Attributes.numPages#">
  38.  
  39. <!--- If the loopcount is the current page, show the page number without a link --->
  40. <cfif LoopCount eq Attributes.curPage>
  41. <span class="curPage">#LoopCount#</span>
  42. <cfelse>
  43. <cfset pageStart = ((LoopCount - 1 ) * Attributes.numPerPage) + 1>
  44. <a href="#Attributes.pageName#?startRow=#pageStart#" class="pageNum">#LoopCount#</a>
  45. </cfif>
  46.  
  47. </cfloop>
  48.  
  49. <!--- If we are not on the last page, show a next button --->
  50. <cfif Attributes.nextPage lte Attributes.queryName.RecordCount>
  51. &nbsp;&nbsp;<a href="#Attributes.pageName#?startRow=#Attributes.nextPage#" class="pageNum"><cfif Attributes.forwardImage neq ""><img src="#Attributes.forwardImage#" border="0" /><cfelse>Next Page&gt;&gt;</cfif></a>
  52. </cfif>
  53.  
  54. </cfoutput>
  55. </cfif>

So, how do you use it? Like this:

ColdFusion Syntax (Toggle Plain Text)
  1. <!--- Set Default values --->
  2. <cfparam name="startRow" default="1">
  3. <cfparam name="nextPage" default="">
  4. <cfparam name="prevPage" default="">
  5. <cfparam name="numPerPage" default="20">
  6. <cfparam name="numPages" default="0">
  7. <cfparam name="curPage" default="1">
  8.  
  9. <cf_pageNumSetup queryName="qryQuery" />
  10.  
  11. <cf_pageNum forwardImage="next.gif" backImage="previous.gif" pageName="Index.cfm" />

Let me know how that works for you...
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008
Jul 29th, 2008
0

Re: navigation button

hiiii
ya the navigation button works correctly and perfectly.
thnk
Reputation Points: 10
Solved Threads: 0
Light Poster
nish88 is offline Offline
46 posts
since Nov 2007
Jul 29th, 2008
0

Re: navigation button

Anytime. Glad to help.
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ColdFusion Forum Timeline: insert loop
Next Thread in ColdFusion Forum Timeline: A little help with some coldfusion theroy and code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC