I’m John C Bland II

Husband, Father, Tech Author, Deacon.
Founder of Katapult Media, and full-stack polyglot developer.
Political Free Agents Podcast Host.

I create. I launch.

YouTube Channel

I post regular fun on YouTube like me playing the bass and anything else I find fun. 

Get Something Built

All project work goes through Katapult Media. Business is open. Let’s chat.

I had some problems with this because I’m so used to using datagrids in Flash and they work a bit different. First, there aren’t a ton of resources out there about binding a cfgrid to a cfselect. I looked and looked but I shouldn’t have since the reason my initial statements weren’t working is because I treated the cfgrid like a Flash datagrid. So, let’s get into it.

Binding a cfselect to a grid is as simple as this:

bq. <cfgrid name=”mygrid” format=”html” query=”somequery” />
<cfselect name=”myselect” bind=”cfc:somecfc.someMethod({mygrid.id})” bindonload=”yes” … />

That’s it. What happens here is the _bind_ attribute sets the bind to my _somecfc_ cfc’s _someMethod()_ function and passes in the _id_ value from _mygrid_. Nothing special here.

So, why did I have problems? Well, I didn’t let the query create my columns. I created them. Let’s take a look at this again.

bq. <cfgrid name=”mygrid” format=”html” query=”somequery”>
<cfgridcolumn header=”Name” name=”name” />
<cfgridcolumn header=”Some Column” name=”somecolumn” />
<cfgridcolumn header=”Birthday” name=”birthday” />
</cfgrid>

<cfselect name=”myselect” bind=”cfc:somecfc.someMethod({mygrid.id})” bindonload=”yes” … />

The difference here is the _cfgridcolumn_’s specify what columns are shown. The first example will show all of the columns in the grid. This grid (the second example) shows only the _name_, _somecolumn_, and _birthday_ columns. Any other columns are not available.

This _cfselect_ bind will not work. The problem is there is no such column named _id_. BUT THE QUERY HAS AN _id_ COLUMN…WHY ISN’T IT INCLUDED? I’m glad you asked.

If you do not specifically specify a _cfgridcolumn_ the value will not be included. When you think about it…this is pretty cool. Think of a query with 20 columns. I wouldn’t want a grid to have to manage 20 columns if all I want to show are three of them. It is annoying but it works.

So, the working example would be:

bq. bq. <cfgrid name=”mygrid” format=”html” query=”somequery”>
<cfgridcolumn header=”id” name=”id” display=”no” />
<cfgridcolumn header=”Name” name=”name” />
<cfgridcolumn header=”Some Column” name=”somecolumn” />
<cfgridcolumn header=”Birthday” name=”birthday” />
</cfgrid>

<cfselect name=”myselect” bind=”cfc:somecfc.someMethod({mygrid.id})” bindonload=”yes” … />

Notice the _cfgridcolumn_ with the name _id_. The attribute _display_ is set to _no_ so it will not show up in the grid. Now the _cfselect_’s binding will work properly.

I searched the WHOLE INTERNET for this solution and didn’t find it. I saw an example with the same binding as I was using, _mygrid.somecolumn_, but it wouldn’t work for me. At least I have the solution now. I guess I should have read the manual. 🙂

Hope this helps someone.