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 max2007 max2008 misc open source programming railo software technology ui
Recent Entries
Converting structkeys to lowercase
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.