DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ColdFusion (http://www.daniweb.com/forums/forum19.html)
-   -   navigation button (http://www.daniweb.com/forums/thread134343.html)

nish88 Jul 14th, 2008 10:20 am
navigation button
 
have anyone ever creates navigation buttons such as next,previous in coldfusion?

can i see ours if you have created one?

cmhampton Jul 14th, 2008 8:03 pm
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.

nish88 Jul 15th, 2008 1:47 am
Re: navigation button
 
ya its based on query.
so thanks in advance..;)

cmhampton Jul 15th, 2008 9:51 am
Re: navigation button
 
Are you permitted by your hosting company to use custom tags?

nish88 Jul 16th, 2008 2:38 am
Re: navigation button
 
ya am permitted

cmhampton Jul 16th, 2008 3:10 am
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.

cmhampton Jul 16th, 2008 12:01 pm
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:

<!--- pageNumSetup.cfm --->

<cfscript>
        // round page number variable up
        function roundPageNum(number) {
               
                var x = 0;
               
                x = Int(number);
               
                if(number - x neq 0) {
                        x = x + 1;
                }
               
                return x;
        }
</cfscript>

<!--- Set Default values --->
<cfparam name="Caller.startRow" default="1">
<cfparam name="Caller.nextPage" default="">
<cfparam name="Caller.prevPage" default="">
<cfparam name="Caller.numPerPage" default="20">
<cfparam name="Caller.numPages" default="0">
<cfparam name="Caller.curPage" default="1">
<cfparam name="Attributes.queryName" default="">

<!--- Set values for previous and next pages --->
<cfset Caller.nextPage = Caller.startRow + Caller.numPerPage>
<cfset Caller.prevPage = Caller.startRow - Caller.numPerPage>

<!--- Determine the total number of pages for this search --->
<cfset Caller.numPages = Attributes.queryName.RecordCount / Caller.numPerPage >
<cfset Caller.numPages = roundPageNum(Caller.numPages)>
<cfset Caller.curPage = ((Caller.startrow -1) / Caller.numPerPage) + 1>

Now for the navigation links:

<!--- pageNum.cfm --->

<!--- Set Default values --->
<cfparam name="Caller.startRow" default=""> <!--- Numeric --->
<cfparam name="Caller.nextPage" default=""> <!--- Numeric --->
<cfparam name="Caller.prevPage" default=""> <!--- Numeric --->
<cfparam name="Caller.numPerPage" default="20"> <!--- Numeric --->
<cfparam name="Caller.numPages" default=""> <!--- Numeric --->
<cfparam name="Caller.curPage" default=""> <!--- Numeric --->
<cfparam name="Caller.queryName" default=""> <!--- Query --->
<cfparam name="Attributes.forwardImage" default=""> <!--- string --->
<cfparam name="Attributes.backImage" default=""> <!--- string --->

<!--- This variable is used to direct the links to the correct template --->
<cfparam name="Attributes.pageName" default="Index.cfm">  <!--- string --->

<!--- If there is only one page of results, there is no need to show links --->
<cfif Attributes.queryName.RecordCount LT Attributes.numPerPage>
        <span class="curPage">Page 1 of 1</span>
<cfelse>

        <cfoutput>

                <!--- If this is not the first page, show a link to the previous --->
                <cfif Attributes.prevPage gt 0>
                        <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;
                </cfif>
               
        <!--- If this is the first page, show the page number without a link --->
                <cfif Attributes.curPage eq 1>
                        <span class="curPage">1</span>
                <cfelse>
                        <a href="#Attributes.pageName#?startRow=1" class="pageNum">1</a>
                </cfif>
               
        <!--- Loop through the number of pages and create the links --->
                <cfloop index="LoopCount" from="2" to="#Attributes.numPages#">
               
                <!--- If the loopcount is the current page, show the page number without a link --->
                        <cfif LoopCount eq Attributes.curPage>
                                <span class="curPage">#LoopCount#</span>
                        <cfelse>
                                <cfset pageStart = ((LoopCount - 1 ) * Attributes.numPerPage) + 1>
                                <a href="#Attributes.pageName#?startRow=#pageStart#" class="pageNum">#LoopCount#</a>
                        </cfif>
               
                </cfloop>
               
        <!--- If we are not on the last page, show a next button --->
                <cfif Attributes.nextPage lte Attributes.queryName.RecordCount>
                        &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>
                </cfif>
               
        </cfoutput>
</cfif>

So, how do you use it? Like this:

<!--- Set Default values --->
<cfparam name="startRow" default="1">
<cfparam name="nextPage" default="">
<cfparam name="prevPage" default="">
<cfparam name="numPerPage" default="20">
<cfparam name="numPages" default="0">
<cfparam name="curPage" default="1">

<cf_pageNumSetup queryName="qryQuery" />

<cf_pageNum forwardImage="next.gif" backImage="previous.gif" pageName="Index.cfm" />

Let me know how that works for you...

nish88 Jul 29th, 2008 10:31 am
Re: navigation button
 
hiiii
ya the navigation button works correctly and perfectly.
thnk

cmhampton Jul 29th, 2008 1:16 pm
Re: navigation button
 
Anytime. Glad to help.


All times are GMT -4. The time now is 4:30 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC