Coldfusion 8 and cfgrid pagination
Tags: Coldfusion
After working on a similar thing for a client using extJS I decided to try the same thing in the new Ajax/UI features of Coldfusion 8 and boy was it easy to do.
I wish that the client could afford to upgrade to CF8.. Anyway the following is a reference more for people looking to do the sql code for this new feature.
This is all very self explanatory so I post the code and explain, to anyone who wishes to know more.
<cfform name="tableform">
<cfgrid format="html" name="grid_Tables" pagesize="7" selectmode="row"
bind="cfc:components.artgallery.artist.getArtists({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">
<cfgridcolumn name="ARTISTID" display="No"/>
<cfgridcolumn name="FIRSTNAME" header="FIRSTNAME" >
<cfgridcolumn name="LASTNAME" header="LASTNAME" >
<cfgridcolumn name="CITY" header="CITY" >
<cfgridcolumn name="STATE" header="STATE" >
</cfgrid>
</cfform>
<cfgrid format="html" name="grid_Tables" pagesize="7" selectmode="row"
bind="cfc:components.artgallery.artist.getArtists({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">
<cfgridcolumn name="ARTISTID" display="No"/>
<cfgridcolumn name="FIRSTNAME" header="FIRSTNAME" >
<cfgridcolumn name="LASTNAME" header="LASTNAME" >
<cfgridcolumn name="CITY" header="CITY" >
<cfgridcolumn name="STATE" header="STATE" >
</cfgrid>
</cfform>
And the cfc component is as follows.
<cffunction name="getArtists" access="remote">
<cfargument name="page" required="yes">
<cfargument name="pageSize" required="yes">
<cfargument name="gridsortcolumn" required="yes">
<cfargument name="gridsortdirection" required="yes">
<cfquery name="members" datasource="cfartgallery">
SELECT TOP #pagesize# ARTISTID, FIRSTNAME, LASTNAME, CITY, STATE
FROM ARTISTS
WHERE (ARTISTID NOT IN
(SELECT TOP #page# ARTISTID
FROM ARTISTS AS ARTISTS1 ORDER BY ARTISTID))
ORDER BY ARTISTID
</cfquery>
<cfreturn queryconvertforgrid(members,page,pagesize)/>
</cffunction>
<cfargument name="page" required="yes">
<cfargument name="pageSize" required="yes">
<cfargument name="gridsortcolumn" required="yes">
<cfargument name="gridsortdirection" required="yes">
<cfquery name="members" datasource="cfartgallery">
SELECT TOP #pagesize# ARTISTID, FIRSTNAME, LASTNAME, CITY, STATE
FROM ARTISTS
WHERE (ARTISTID NOT IN
(SELECT TOP #page# ARTISTID
FROM ARTISTS AS ARTISTS1 ORDER BY ARTISTID))
ORDER BY ARTISTID
</cfquery>
<cfreturn queryconvertforgrid(members,page,pagesize)/>
</cffunction>
Please enjoy...
-
You said: "cfreturn queryconvertforgrid(members,page,pagesize)". This seems to mean the queryname,page,pagesize.
When I do this (with my queryname 'selectall' and my file named comments.cfc), I get an error that tells me "The specified remote function selectall was not found on the CFC comments." Any ideas?
I thought CFGRID did pagination easily from all the neat demos bragging about it. It's only taken me an entire day of googling/reading to figure out that 'easily' is a very subjective term apparently. Html form with query making it impossible, CFC required, etc. I'm learning all this and have read tons of blogs and the documents but when nearly every point is new (I last worked with CF 2 versions ago) it's frustrating...# Posted By PJ | 8/1/08 2:00 PM -
PJ,
Sorry for not getting back to you any soon on this, I am not sure if you have solved your issue. The error that you have described, appears to be because you might not have access="remote" as part of your cffunction code.
Let me know, how you go, at least that would be my first suggestion.
# Posted By Andrew Scott | 8/24/08 6:55 AM



TweetBacks