Filtering CFGrid with CFSelect
A reader asked me yesterday about filtering a CFGrid using a CFSelect. I am quite happy to say that it is dead easy to do using the new CF8 tags. You can also bind your CFGrid to more than one control you just need to handle it with your cffunction.
Take the following grid for example. The grid is bound to a tree control as well as another control. The tree control sends the directory to the geFiles function to return a list of files.
<cfgrid name="fileGrid" format="html" sort="true"
bind="cfc:#request.cfcpath#fileExplorer.fileExplorer.getfiles({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},{mytree:directories.node},{extensions})">
<cfgridcolumn name="name" header="File Name" display="true"/>
<cfgridcolumn name="size" header="Size" display="true"/>
<cfgridcolumn name="datelastModified" header="Last Modified" width="150"/>
<cfgridcolumn name="directory" header="" display="true"/>
</cfgrid>
The extensions control is cfselect that returns a list of file extensions that the results can be filtered with. The default item in the select control is an empty string which will indicate to the CFC not to filter the items.
<cfselect name="extensions" bind="cfc:#request.cfcpath#fileExplorer.fileExplorer.getfileExtensions()" bindonload="true">
Then in the CFC need to make sure that you have the required grid arguments as well as the optional arguments.
<cfargument name="page" type="numeric" required="yes"/>
<cfargument name="pageSize" type="numeric" required="yes"/>
<cfargument name="gridSortColumn" type="string" required="yes"/>
<cfargument name="gridSortDirection" type="string" required="yes"/>
<cfargument name="path" type="string" required="false" default="/"/>
<cfargument name="filter" type="string" required="false" default="">
And there you have it, a CFGrid that is bound to two different controls, a tree control and a cfselect.
Happy Coding...

Subscribe
Subscribe via RSS
Follow me on Twitter
Or, Receive daily updates via email.
Tags
adobe air ajax apple cf community cfml coldfusion examples ext flash flex google javascript jquery max2007 max2008 misc open source programming railo software technology ui
Recent Entries
No recent entries.
Blogroll
An Architect's View
CFSilence
Rey Bango
TalkingTree

can you please post your cfc so I can see your query? I'm trying to filter a query with paging but I'm running into the problem that it only filters by page. I want it to filter all on the first page and go to another page if more data is present for page 2. Does that make since? It filtering by each page...
what seems to be simple like this example and nothing works.
The folks over at ASFusion did a great tutorial back in 2005 on how you can populate the cfgrid with flash remoting. Check our the post http://www.asfusion.com/blog/entry/populating-a-cf...
I have a cfgrid that appears within a cfwindow when a user clicks in a textbox via onclick="ColdFusion.Window.show('userWin')". The grid is populated with clients from the database. I am trying to figure out how to bind the hidden id attribute of the client to the textbox. Would I use something like bind="cfgrid.id" to make the client's username appear in the textbox and dismiss the cfwindow?
Thanks in advance.
Another 'binding variables' question...
How can I use a url variable as a pass parameter in my cfgrid binding statement, in order to use it in my SQL WHERE clause?
For instance...I want to pass #url.myVar# into my cfgrid, as I am going to use it in my WHERE clause in my function. Heres the cfgrid:
(NOTE: the url.myVar is exists on the same page, begore I call cfgrid)
<cfgrid name="10CEItoSS"
format="html"
pagesize="10"
striperows="yes"
bind="cfc:SRTVManager.getCEItoSS({cfgridpage},
{cfgridpagesize},
{cfgridsortcolumn},
{cfgridsortdirection})"> <------DO I NEED TO ADD ANOTHER VAR HERE ??
<cfgridcolumn name="CNum" header="CEI" width="75"/>
<cfgridcolumn name="CSect" header="Section" width="30"/>
<cfgridcolumn name="CPara" header="Para" width="100"/>
<cfgridcolumn name="SSNum" header="Subsys Doc." width="100"/>
<cfgridcolumn name="SSSect" header="Section" width="30"/>
<cfgridcolumn name="SSPara" header="Para" width="100"/>
</cfgrid>
Here's the function in my cfc:
<cffunction name="getCEItoSS" access="remote" returntype="struct" output="false">
<cfargument name="cfgridpage" type="numeric" required="no">
<cfargument name="cfgridpagesize" type="numeric" required="no">
<cfargument name="cfgridsortcolumn" type="string" required="no">
<cfargument name="cfgridsortdirection" type="string" required="no">
<cfargument name="p1" type="string" required="yes" default=""> //I don't know if this is correct ???
<!---Retieve 10CEI to Subsys doc --->
<cfquery name="get_10cei_subsys" datasource="#this.dsn#" blockfactor="100">
SELECT DISTINCT SRT_Contract_Rqt.Contract_No As CNum blah, blah...
FROM SRT_Contract_Rqt INNER JOIN blah, blah
WHERE (((SRT_Contract_Rqt.Contract_No)='10CEI-0001') AND ((SRT_SUBSYSTEM.SS_LLD_No)=#p1#))
ORDER BY SRT_Contract_Rqt.Para
<cfreturn queryConvertForGrid(get_10cei_subsys,arguments.cfgridpage,arguments.cfgridpagesize)>
</cfquery>
</cffunction>
I want to pass that #p1# into my WHERE clause from the 'bind' statement from the cfgrid....any help would be appreciated!
Been scouring google on this one....nothing.
You can bind additional parameters to your bind parameters. You would use the curly braces for example next to cfgridsortdirection as you indicated in your comment. You have to bind to a field that is located in a cfform, eg {myform:fieldname}, which means that the value of your fieldname should be the url variable.
I dont' believe you can bind your grid to a url variable, though you could give it a try e.g. {url:myvar} and if that doesnt work use a hidden form field in your cfform.
suggestions...thx!
I run the code in Firefox with Firebug, and my query result (227 records)
is all 'nulls'. My grid appears (thanks to the previous fix), but with no data,
and firebug shows all nulls being returned for all the records. Any idea
what's going on?? Thanks in advance...
GK
(NOTE: the value of variables.p1 is "10SPC-0188")
Here my cfform, cfgrid with the fix:
<cfform name="myForm">
<input name="getURLVar" type="hidden" value="#variables.p1#" />
<cfgrid name="10CEItoSS"
format="html"
sort="yes"
pagesize="10"
striperows="yes" selectmode="row"
bind="cfc:SRTVManager.getCEItoSS({cfgridpage},
{cfgridpagesize},
{cfgridsortcolumn},
{cfgridsortdirection},
{myForm:getURLVar})">
<cfgridcolumn name="CNum" header="CEI" width="75"/>
<cfgridcolumn name="CSect" header="Section" width="30"/>
<cfgridcolumn name="CPara" header="Para" width="100"/>
<cfgridcolumn name="SSNum" header="Subsys Doc." width="100"/>
<cfgridcolumn name="SSSect" header="Section" width="30"/>
<cfgridcolumn name="SSPara" header="Para" width="100"/>
</cfgrid>
</cfform>
Result: no data returned to grid...firebug shows nulls (query didn't work).
Then, I did this in my bind statement:
bind="cfc:SRTVManager.getCEItoSS({cfgridpage},
{cfgridpagesize},
{cfgridsortcolumn},
{cfgridsortdirection},
'10SPC-0188')">
I passed the literal value, no curly braces...it worked! I get my data :)
So we have a syntax issue, how do I make that pass parameter get resolved
into the query....{myForm:getURLVar} isn't working, not seeing the value.