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...

7 Comments to "Filtering CFGrid with CFSelect"- Add Yours
knk's Gravatar Hi,
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...
# Posted By knk | 10/17/08 8:19 PM
Gary's Gravatar The CFC has been posted previously you can see the interesting part here http://www.garyrgilbert.com/blog/index.cfm/2007/7/...
# Posted By Gary | 10/19/08 1:22 AM
mike's Gravatar does this actually work? is there any documentation on the rules for binding in a cfform when it is flash? we have spent weeks trying to
what seems to be simple like this example and nothing works.
# Posted By mike | 3/9/09 5:54 AM
Gary's Gravatar unfortunately the bind attribute is only available for html based grids. If you want to have your flash based grid auto update you are going to have to do it using actionscript.

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...
# Posted By Gary | 3/10/09 7:12 PM
manda's Gravatar I have 5 form input fields and a button. I need to refresh the grid on click of the button only by passing the 5 input field values. But the grid is getting called as soon as i enter one or other input fields.. how can i resolve this?
# Posted By manda | 4/17/09 11:07 PM
Gary Gilbert's Gravatar You are probably attached to the onchange event in the grid, you dont want to bind the grid at all in this case but call the refresh function on the click of the button
# Posted By Gary Gilbert | 4/17/09 2:01 AM
Adam's Gravatar Hi Gary -

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.
# Posted By Adam | 7/28/09 4:57 AM

Powered By Railo

Subscribe

Subscribe via RSS
Follow garyrgilbert on Twitter 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

Wish List

My Amazon.com Wish List