Saturday 17 May 2008   
Add Comment

Paging With CFGRID Tutorial

ColdFusion Tutorial #1

This tutorial shows how simple it is to do paging of a recordset using CFGRID.

demo.cfm

This is very simple, firstly you just setup a grid by defining a grid and the columns. This is done using the <cfgrid and <cfgridcolumn tags very straight forward.

On line 2, the cfgrid line, add a binding, and yes all those bind attributes are required, it's so that the cfc can return the right set of records for the page you are on.

cfgridpage = what page the grid is on
cfgridpagesize = how many records are displayed per page
cfgridsortcolumn = the selected column to sort
cfgridsortdirection = the sort direction

These get sent to the cfc so that it can pull apart the query and return the right information.

 
 


park.cfc

The cfc is just as simple, receive all those required paramaters (lines 2-5). Lines (7-10) defines a default sort order because the first time you run a grid, you haven't clicked the column header.

Now you can do a query as normal, make sure you return all the columns you need for the grid or you will get an error. And you can use the sort arguments to define the sort order.

Line 18 takes the query and only returns the part of the query you need to display the page. That's it, very easy for this level of functionality. This returns a structure and not a query, note the function return type. So it will only send your browser the records it needs to display the current page.

 
 


Demo

See this code running!


Download

Download this code as a zip!


Comments

Trying to get this working locally and having real issues.
We keep coming up against this js error
'Exception thrown and not caught'
The grid just has the headers and page numbers - but no data even though I can see the data been returned by using cfdebug on the url
Paul Hopkinson @ Wednesday 17 Oct 2007 - 10:36:33 PM

What version of ColdFusion is this because in 7 you can't use bind and pagesize in version 7.02
Syd @ Tuesday 18 Dec 2007 - 05:09:32 AM

It's Version 8
Dale Fraser @ Tuesday 18 Dec 2007 - 12:10:12 PM

Yeah getting the same problem and I'm running CF V8
Craig @ Monday 18 Feb 2008 - 10:55:56 PM

Make sure you have a CFIDE virtual directory under your site, this is needed for the Ajax includes.
Dale Fraser @ Wednesday 20 Feb 2008 - 01:08:38 PM

How to add CFIDE virtual directory.
Ram @ Wednesday 12 Mar 2008 - 11:20:31 AM

It depens on your config.
In IIS you just create a virtual directory called CFIDE pointing to the C:\ColdFusion8\wwwroot\CFIDE directory.
Dale Fraser @ Wednesday 12 Mar 2008 - 01:04:03 PM

I have Built in ColdFusion Server on my desktop so where do I include my dir mapping, I have it mapped in CF Admin.
And do we need cfajaxproxy for this.

Ram @ Thursday 13 Mar 2008 - 06:43:29 AM

This will be included in the CF8 install, if you can browse to the administrator then it's working and your problem must be elsewhere.
Dale Fraser @ Thursday 13 Mar 2008 - 08:45:18 AM

When execute this code in my local machine it give an error.
Error invoking CFC /park.cfc : Not Found
manoj kothari @ Thursday 01 May 2008 - 08:23:26 PM

Click button to add a comment


Author

Dale Fraser


Published

Tuesday 28 Aug 2007

Tags

cfargument  cfform  cffunction  cfgrid  cfgridcolumn  cfif  cfquery  cfreturn  cfset