Skip to content

Instantly share code, notes, and snippets.

@codesharpdev
Forked from steinbring/pagination.cfm
Created August 16, 2017 12:51
Show Gist options
  • Save codesharpdev/512aa88bdf18bee8f7f1fe820c76b3e5 to your computer and use it in GitHub Desktop.
Save codesharpdev/512aa88bdf18bee8f7f1fe820c76b3e5 to your computer and use it in GitHub Desktop.

Revisions

  1. @steinbring steinbring revised this gist Dec 17, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pagination.cfm
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    <cfset intMaxLinkToShow = ceiling(intNumberOfTotalItems / intItemsPerPage)>
    </cfif>
    <!--- Should I show the back button? --->
    <cfif intMaxLinkToShow - intPagesToLinkTo EQ 0>
    <cfif intMaxLinkToShow - intPagesToLinkTo LTE 0>
    <cfset boolShowBackButton = 0>
    <cfelse>
    <cfset boolShowBackButton = 1>
  2. @steinbring steinbring revised this gist Dec 17, 2012. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions pagination.cfm
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    <!--- What page are you currently on? --->
    <cfset intSelection = 5>
    <!--- How many pages should you link to at any one time? --->
    <cfset intPagesToLinkTo = 5>
    <!--- How many items are you displaying per page? --->
  3. @steinbring steinbring revised this gist Dec 17, 2012. 1 changed file with 36 additions and 36 deletions.
    72 changes: 36 additions & 36 deletions pagination.cfm
    Original file line number Diff line number Diff line change
    @@ -17,66 +17,66 @@
    <cfset intMinLinkToShow = (int(variables.intCurrentPage/intPagesToLinkTo)*intPagesToLinkTo)+1>
    <!--- Is intMaxLinkToShow equal to the unadjusted intMinLinkToShow value? If so, reset intMinLinkToShow to be where it should be. --->
    <cfif intMaxLinkToShow eq (int(variables.intCurrentPage/intPagesToLinkTo)*intPagesToLinkTo)>
    <cfset intMinLinkToShow = intMaxLinkToShow - (intPagesToLinkTo - 1)>
    <cfset intMinLinkToShow = intMaxLinkToShow - (intPagesToLinkTo - 1)>
    </cfif>
    <!--- Is intMaxLinkToShow bigger than we need to shouw intNumberOfTotalItems? If so, reset it. Use ceiling() to round it up. --->
    <cfif intMaxLinkToShow gt intNumberOfTotalItems / intItemsPerPage>
    <cfset intMaxLinkToShow = ceiling(intNumberOfTotalItems / intItemsPerPage)>
    <cfset intMaxLinkToShow = ceiling(intNumberOfTotalItems / intItemsPerPage)>
    </cfif>
    <!--- Should I show the back button? --->
    <cfif intMaxLinkToShow - intPagesToLinkTo EQ 0>
    <cfset boolShowBackButton = 0>
    <cfset boolShowBackButton = 0>
    <cfelse>
    <cfset boolShowBackButton = 1>
    <cfset boolShowBackButton = 1>
    </cfif>
    <!--- Should I show the forward button? --->
    <cfif ceiling(intNumberOfTotalItems / intItemsPerPage) lte intMaxLinkToShow>
    <cfset boolShowForwardButton = 0>
    <cfset boolShowForwardButton = 0>
    <cfelse>
    <cfset boolShowForwardButton = 1>
    <cfset boolShowForwardButton = 1>
    </cfif>
    <!--- What items should I show on the page? --->
    <cfset intMinItemsToShow = (intItemsPerPage * (intCurrentPage - 1))+ 1>
    <cfset intMaxItemsToShow = intMinItemsToShow + intItemsPerPage - 1>
    <!--- Have you reached the maximum number of items to show? --->
    <cfif intMaxItemsToShow gt intNumberOfTotalItems>
    <cfset intMaxItemsToShow = intNumberOfTotalItems>
    <cfset intMaxItemsToShow = intNumberOfTotalItems>
    </cfif>


    <!--- Display the results --->
    <div>
    <cfloop from="#variables.intMinItemsToShow#" to="#variables.intMaxItemsToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:10px;padding:20px;border:1px solid black;">
    <cfoutput>#i#</cfoutput>
    </div>
    </cfloop>
    <cfloop from="#variables.intMinItemsToShow#" to="#variables.intMaxItemsToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:10px;padding:20px;border:1px solid black;">
    <cfoutput>#i#</cfoutput>
    </div>
    </cfloop>
    </div>
    <!--- Display the pagination buttons --->
    <div style="clear:both; margin-top:10px;">
    <!--- Show a "back button" that link to the smallest number page - 1 --->
    <cfif variables.boolShowBackButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMinLinkToShow-1#</cfoutput>">&lt;</a>
    </div>
    </cfif>
    <!--- Loop through and create links to intPagesToLinkTo pages --->
    <cfloop from="#variables.intMinLinkToShow#" to="#variables.intMaxLinkToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <cfoutput>
    <cfif intCurrentPage eq i>
    #i#
    <cfelse>
    <a href="?page=#i#">#i#</a>
    </cfif>
    </cfoutput>
    </div>
    </cfloop>
    <!--- Show a "forward button" that links to the largest number page + 1 --->
    <cfif variables.boolShowForwardButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMaxLinkToShow+1#</cfoutput>">&gt;</a>
    </div>
    </cfif>
    <!--- Show a "back button" that link to the smallest number page - 1 --->
    <cfif variables.boolShowBackButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMinLinkToShow-1#</cfoutput>">&lt;</a>
    </div>
    </cfif>
    <!--- Loop through and create links to intPagesToLinkTo pages --->
    <cfloop from="#variables.intMinLinkToShow#" to="#variables.intMaxLinkToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <cfoutput>
    <cfif intCurrentPage eq i>
    #i#
    <cfelse>
    <a href="?page=#i#">#i#</a>
    </cfif>
    </cfoutput>
    </div>
    </cfloop>
    <!--- Show a "forward button" that links to the largest number page + 1 --->
    <cfif variables.boolShowForwardButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMaxLinkToShow+1#</cfoutput>">&gt;</a>
    </div>
    </cfif>
    </div>
    <div style="clear:both;"></div>
  4. @steinbring steinbring revised this gist Dec 17, 2012. 1 changed file with 36 additions and 36 deletions.
    72 changes: 36 additions & 36 deletions pagination.cfm
    Original file line number Diff line number Diff line change
    @@ -17,66 +17,66 @@
    <cfset intMinLinkToShow = (int(variables.intCurrentPage/intPagesToLinkTo)*intPagesToLinkTo)+1>
    <!--- Is intMaxLinkToShow equal to the unadjusted intMinLinkToShow value? If so, reset intMinLinkToShow to be where it should be. --->
    <cfif intMaxLinkToShow eq (int(variables.intCurrentPage/intPagesToLinkTo)*intPagesToLinkTo)>
    <cfset intMinLinkToShow = intMaxLinkToShow - (intPagesToLinkTo - 1)>
    <cfset intMinLinkToShow = intMaxLinkToShow - (intPagesToLinkTo - 1)>
    </cfif>
    <!--- Is intMaxLinkToShow bigger than we need to shouw intNumberOfTotalItems? If so, reset it. Use ceiling() to round it up. --->
    <cfif intMaxLinkToShow gt intNumberOfTotalItems / intItemsPerPage>
    <cfset intMaxLinkToShow = ceiling(intNumberOfTotalItems / intItemsPerPage)>
    <cfset intMaxLinkToShow = ceiling(intNumberOfTotalItems / intItemsPerPage)>
    </cfif>
    <!--- Should I show the back button? --->
    <cfif intMaxLinkToShow - intPagesToLinkTo EQ 0>
    <cfset boolShowBackButton = 0>
    <cfset boolShowBackButton = 0>
    <cfelse>
    <cfset boolShowBackButton = 1>
    <cfset boolShowBackButton = 1>
    </cfif>
    <!--- Should I show the forward button? --->
    <cfif ceiling(intNumberOfTotalItems / intItemsPerPage) lte intMaxLinkToShow>
    <cfset boolShowForwardButton = 0>
    <cfset boolShowForwardButton = 0>
    <cfelse>
    <cfset boolShowForwardButton = 1>
    <cfset boolShowForwardButton = 1>
    </cfif>
    <!--- What items should I show on the page? --->
    <cfset intMinItemsToShow = (intItemsPerPage * (intCurrentPage - 1))+ 1>
    <cfset intMaxItemsToShow = intMinItemsToShow + intItemsPerPage - 1>
    <!--- Have you reached the maximum number of items to show? --->
    <cfif intMaxItemsToShow gt intNumberOfTotalItems>
    <cfset intMaxItemsToShow = intNumberOfTotalItems>
    <cfset intMaxItemsToShow = intNumberOfTotalItems>
    </cfif>


    <!--- Display the results --->
    <div>
    <cfloop from="#variables.intMinItemsToShow#" to="#variables.intMaxItemsToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:10px;padding:20px;border:1px solid black;">
    <cfoutput>#i#</cfoutput>
    </div>
    </cfloop>
    <cfloop from="#variables.intMinItemsToShow#" to="#variables.intMaxItemsToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:10px;padding:20px;border:1px solid black;">
    <cfoutput>#i#</cfoutput>
    </div>
    </cfloop>
    </div>
    <!--- Display the pagination buttons --->
    <div style="clear:both; margin-top:10px;">
    <!--- Show a "back button" that link to the smallest number page - 1 --->
    <cfif variables.boolShowBackButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMinLinkToShow-1#</cfoutput>">&lt;</a>
    </div>
    </cfif>
    <!--- Loop through and create links to intPagesToLinkTo pages --->
    <cfloop from="#variables.intMinLinkToShow#" to="#variables.intMaxLinkToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <cfoutput>
    <cfif intCurrentPage eq i>
    #i#
    <cfelse>
    <a href="?page=#i#">#i#</a>
    </cfif>
    </cfoutput>
    </div>
    </cfloop>
    <!--- Show a "forward button" that links to the largest number page + 1 --->
    <cfif variables.boolShowForwardButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMaxLinkToShow+1#</cfoutput>">&gt;</a>
    </div>
    </cfif>
    <!--- Show a "back button" that link to the smallest number page - 1 --->
    <cfif variables.boolShowBackButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMinLinkToShow-1#</cfoutput>">&lt;</a>
    </div>
    </cfif>
    <!--- Loop through and create links to intPagesToLinkTo pages --->
    <cfloop from="#variables.intMinLinkToShow#" to="#variables.intMaxLinkToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <cfoutput>
    <cfif intCurrentPage eq i>
    #i#
    <cfelse>
    <a href="?page=#i#">#i#</a>
    </cfif>
    </cfoutput>
    </div>
    </cfloop>
    <!--- Show a "forward button" that links to the largest number page + 1 --->
    <cfif variables.boolShowForwardButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMaxLinkToShow+1#</cfoutput>">&gt;</a>
    </div>
    </cfif>
    </div>
    <div style="clear:both;"></div>
  5. @steinbring steinbring revised this gist Dec 17, 2012. 1 changed file with 37 additions and 37 deletions.
    74 changes: 37 additions & 37 deletions pagination.cfm
    Original file line number Diff line number Diff line change
    @@ -10,73 +10,73 @@
    <cfif isdefined("url.page")>
    <cfset intCurrentPage = val(url.page)>
    <cfelse>
    <cfset intCurrentPage = 1>
    <cfset intCurrentPage = 1>
    </cfif>
    <!--- Find the closest numbers to intCurrentPage that is divisible by intPagesToLinkTo --->
    <cfset intMaxLinkToShow = ceiling(variables.intCurrentPage/intPagesToLinkTo)*intPagesToLinkTo>
    <cfset intMinLinkToShow = (int(variables.intCurrentPage/intPagesToLinkTo)*intPagesToLinkTo)+1>
    <!--- Is intMaxLinkToShow equal to the unadjusted intMinLinkToShow value? If so, reset intMinLinkToShow to be where it should be. --->
    <cfif intMaxLinkToShow eq (int(variables.intCurrentPage/intPagesToLinkTo)*intPagesToLinkTo)>
    <cfset intMinLinkToShow = intMaxLinkToShow - (intPagesToLinkTo - 1)>
    <cfset intMinLinkToShow = intMaxLinkToShow - (intPagesToLinkTo - 1)>
    </cfif>
    <!--- Is intMaxLinkToShow bigger than we need to shouw intNumberOfTotalItems? If so, reset it. Use ceiling() to round it up. --->
    <cfif intMaxLinkToShow gt intNumberOfTotalItems / intItemsPerPage>
    <cfset intMaxLinkToShow = ceiling(intNumberOfTotalItems / intItemsPerPage)>
    <cfset intMaxLinkToShow = ceiling(intNumberOfTotalItems / intItemsPerPage)>
    </cfif>
    <!--- Should I show the back button? --->
    <cfif intMaxLinkToShow - intPagesToLinkTo EQ 0>
    <cfset boolShowBackButton = 0>
    <cfset boolShowBackButton = 0>
    <cfelse>
    <cfset boolShowBackButton = 1>
    <cfset boolShowBackButton = 1>
    </cfif>
    <!--- Should I show the forward button? --->
    <cfif ceiling(intNumberOfTotalItems / intItemsPerPage) lte intMaxLinkToShow>
    <cfset boolShowForwardButton = 0>
    <cfset boolShowForwardButton = 0>
    <cfelse>
    <cfset boolShowForwardButton = 1>
    <cfset boolShowForwardButton = 1>
    </cfif>
    <!--- What items should I show on the page? --->
    <cfset intMinItemsToShow = (intItemsPerPage * (intCurrentPage - 1))+ 1>
    <cfset intMaxItemsToShow = intMinItemsToShow + intItemsPerPage - 1>
    <!--- Have you reached the maximum number of items to show? --->
    <cfif intMaxItemsToShow gt intNumberOfTotalItems>
    <cfset intMaxItemsToShow = intNumberOfTotalItems>
    <cfset intMaxItemsToShow = intNumberOfTotalItems>
    </cfif>


    <!--- Display the results --->
    <div>
    <cfloop from="#variables.intMinItemsToShow#" to="#variables.intMaxItemsToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:10px;padding:20px;border:1px solid black;">
    <cfoutput>#i#</cfoutput>
    </div>
    </cfloop>
    <cfloop from="#variables.intMinItemsToShow#" to="#variables.intMaxItemsToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:10px;padding:20px;border:1px solid black;">
    <cfoutput>#i#</cfoutput>
    </div>
    </cfloop>
    </div>
    <!--- Display the pagination buttons --->
    <div style="clear:both; margin-top:10px;">
    <!--- Show a "back button" that link to the smallest number page - 1 --->
    <cfif variables.boolShowBackButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMinLinkToShow-1#</cfoutput>">&lt;</a>
    </div>
    </cfif>
    <!--- Loop through and create links to intPagesToLinkTo pages --->
    <cfloop from="#variables.intMinLinkToShow#" to="#variables.intMaxLinkToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <cfoutput>
    <cfif intCurrentPage eq i>
    #i#
    <cfelse>
    <a href="?page=#i#">#i#</a>
    </cfif>
    </cfoutput>
    </div>
    </cfloop>
    <!--- Show a "forward button" that links to the largest number page + 1 --->
    <cfif variables.boolShowForwardButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMaxLinkToShow+1#</cfoutput>">&gt;</a>
    </div>
    </cfif>
    <!--- Show a "back button" that link to the smallest number page - 1 --->
    <cfif variables.boolShowBackButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMinLinkToShow-1#</cfoutput>">&lt;</a>
    </div>
    </cfif>
    <!--- Loop through and create links to intPagesToLinkTo pages --->
    <cfloop from="#variables.intMinLinkToShow#" to="#variables.intMaxLinkToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <cfoutput>
    <cfif intCurrentPage eq i>
    #i#
    <cfelse>
    <a href="?page=#i#">#i#</a>
    </cfif>
    </cfoutput>
    </div>
    </cfloop>
    <!--- Show a "forward button" that links to the largest number page + 1 --->
    <cfif variables.boolShowForwardButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMaxLinkToShow+1#</cfoutput>">&gt;</a>
    </div>
    </cfif>
    </div>
    <div style="clear:both;"></div>
  6. @steinbring steinbring renamed this gist Dec 17, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. @steinbring steinbring created this gist Dec 17, 2012.
    82 changes: 82 additions & 0 deletions Pagination.cfm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    <!--- What page are you currently on? --->
    <cfset intSelection = 5>
    <!--- How many pages should you link to at any one time? --->
    <cfset intPagesToLinkTo = 5>
    <!--- How many items are you displaying per page? --->
    <cfset intItemsPerPage = 10>
    <!--- How many items do you need to display, across all pages. --->
    <cfset intNumberOfTotalItems = 100>
    <!--- What is the current page you are on? --->
    <cfif isdefined("url.page")>
    <cfset intCurrentPage = val(url.page)>
    <cfelse>
    <cfset intCurrentPage = 1>
    </cfif>
    <!--- Find the closest numbers to intCurrentPage that is divisible by intPagesToLinkTo --->
    <cfset intMaxLinkToShow = ceiling(variables.intCurrentPage/intPagesToLinkTo)*intPagesToLinkTo>
    <cfset intMinLinkToShow = (int(variables.intCurrentPage/intPagesToLinkTo)*intPagesToLinkTo)+1>
    <!--- Is intMaxLinkToShow equal to the unadjusted intMinLinkToShow value? If so, reset intMinLinkToShow to be where it should be. --->
    <cfif intMaxLinkToShow eq (int(variables.intCurrentPage/intPagesToLinkTo)*intPagesToLinkTo)>
    <cfset intMinLinkToShow = intMaxLinkToShow - (intPagesToLinkTo - 1)>
    </cfif>
    <!--- Is intMaxLinkToShow bigger than we need to shouw intNumberOfTotalItems? If so, reset it. Use ceiling() to round it up. --->
    <cfif intMaxLinkToShow gt intNumberOfTotalItems / intItemsPerPage>
    <cfset intMaxLinkToShow = ceiling(intNumberOfTotalItems / intItemsPerPage)>
    </cfif>
    <!--- Should I show the back button? --->
    <cfif intMaxLinkToShow - intPagesToLinkTo EQ 0>
    <cfset boolShowBackButton = 0>
    <cfelse>
    <cfset boolShowBackButton = 1>
    </cfif>
    <!--- Should I show the forward button? --->
    <cfif ceiling(intNumberOfTotalItems / intItemsPerPage) lte intMaxLinkToShow>
    <cfset boolShowForwardButton = 0>
    <cfelse>
    <cfset boolShowForwardButton = 1>
    </cfif>
    <!--- What items should I show on the page? --->
    <cfset intMinItemsToShow = (intItemsPerPage * (intCurrentPage - 1))+ 1>
    <cfset intMaxItemsToShow = intMinItemsToShow + intItemsPerPage - 1>
    <!--- Have you reached the maximum number of items to show? --->
    <cfif intMaxItemsToShow gt intNumberOfTotalItems>
    <cfset intMaxItemsToShow = intNumberOfTotalItems>
    </cfif>


    <!--- Display the results --->
    <div>
    <cfloop from="#variables.intMinItemsToShow#" to="#variables.intMaxItemsToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:10px;padding:20px;border:1px solid black;">
    <cfoutput>#i#</cfoutput>
    </div>
    </cfloop>
    </div>
    <!--- Display the pagination buttons --->
    <div style="clear:both; margin-top:10px;">
    <!--- Show a "back button" that link to the smallest number page - 1 --->
    <cfif variables.boolShowBackButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMinLinkToShow-1#</cfoutput>">&lt;</a>
    </div>
    </cfif>
    <!--- Loop through and create links to intPagesToLinkTo pages --->
    <cfloop from="#variables.intMinLinkToShow#" to="#variables.intMaxLinkToShow#" index="i">
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <cfoutput>
    <cfif intCurrentPage eq i>
    #i#
    <cfelse>
    <a href="?page=#i#">#i#</a>
    </cfif>
    </cfoutput>
    </div>
    </cfloop>
    <!--- Show a "forward button" that links to the largest number page + 1 --->
    <cfif variables.boolShowForwardButton>
    <div style="float:left;font-weight:bold;margin:5px;padding:5px;border:1px solid black;">
    <a href="?page=<cfoutput>#intMaxLinkToShow+1#</cfoutput>">&gt;</a>
    </div>
    </cfif>
    </div>
    <div style="clear:both;"></div>