Avatar of sglee
sglee
 asked on

How to display Navigation buttons in Coldfusion

Hi,
 
 I have items in the table and am displaying 4 items per row. But it displays all items (or records) from the items table.
 How can I add [First][Prev] ....  [Next] [Last] buttons so that each page only displays three rows of items?
 I have also seen [1][2][3] ...[Last] also.
 Both methods will work whichever is simpler.

Thanks.

 Here is the current code:

<TABLE>
      <cfoutput query="GetFeaturedItems">
      <td align="center" >
         <table>
         <tr>
               <TD align="center" bgcolor="white">
                  <table>
                   <tr><td>Title: #Title#</td></tr>
                  <tr><td>Item No:#ItemNo#</td></tr>
                   </table>
                 </TD>
         </tr>
         </table>
      </td>
        <cfif GetFeaturedItems.currentRow mod 4 eq 0>
            <cfif GetFeaturedItems.currentRow gt 1>
                </tr>
            </cfif>
                <tr>
        </cfif>         
        </cfoutput>
</table>
ColdFusion Language

Avatar of undefined
Last Comment
Coast Line

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Coast Line

create a custom tag like this:

Code:

<CFPARAM Name="CurrentPage" Default="1">	<!---	Default the page listing to 1	--->

<!---	Get all products for product listing	--->
<CFQUERY NAME="GetItems" DATASOURCE="#dsn#">
	SELECT * FROM Products
</CFQUERY>

<!---	CF_PageThru will help us break up the product listing into pages.
	The ADDEDPATH parameter is used to pass the search parameter CLASS
	through the links of the generated page-through navigation.
--->
<CF_PAGETHRU TOTALRECORDS="#GetItems.RecordCount#" CURRENTPAGE="#CurrentPage#"
	TEMPLATEURL="#SCRIPT_NAME#" ADDEDPATH="&Class=#Class#">

Open in new window


attached files for pagination, just remove the .txt extension from the end of the cfm file.
CF_PAGETHRU.zip
sglee

ASKER
@Ryan
That worked fine. Thank you.

@myselfrandhawa
I downloaded CF_PAGETHRU.zip and renamed pagethru.txt to pagethru.cfm.
Then I placed pagethru.cfm in the same folder where I have pagination.cfm that has the code in ID: 41019483.
When I run pagination.cfm, I get an error: "Variable CLASS is undefined."
Obviously I did not handle pagethru.cfm correctly.
Coast Line

yes, class is not a mandatory field, you can remove it
Your help has saved me hundreds of hours of internet surfing.
fblack61