Coldfusion 8 Binding a Grid to a Tree

In a previous post I mentioned that I probably wouldn't be using these two tags because they just don't provide me with the flexibility that will allow me to give our customers what they will likely want. But that doesn't completely remove their usefulness, it just reduces it to very specific applications. It still is a good way to demonstrate binding different UI elements together.

As the title states we are going to be binding a tree's select event to a grid. This means that when a user clicks on a node of a tree an Ajax call will be made to repopulate the grid.

Lets pretend for a moment that we have a cfTree named "myTree" in a form called "myTreeForm" and our tree is populated via its own bind call to a cfc that returns directories.


    <cfform name="myTreeForm" >
        <cftree name="myTree" height="400" width="200" format="html">
            <cftreeitem bind="cfc:#request.cfcpath#.fileExplorer.getDirectories({cftreeitempath},{cftreeitemvalue})">
        </cftree>
    </cfform>

Now lets further pretend that we also have a grid called fileGrid in a form called gridform. This grid could be on the same page, or not, but is also subsequently bound to a method in a component that returns files in a specified directory.


<cfform name="gridform" format="html">
    <cfgrid name="fileGrid" format="html" pagesize="10" sort="true"
    bind="cfc:#request.cfcpath#.fileExplorer.getfiles({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},{myTreeForm:myTree.node})">

    <cfgridcolumn name="DIRECTORY" display="false"/>
    <cfgridcolumn name="NAME" header="File Name" display="true"/>
    <cfgridcolumn name="size" header="Size" display="true"/>
    <cfgridcolumn name="datelastModified" header="Last Modified" width="150"/>
    </cfgrid>
</cfform>

The biggest difference in the bind expression here and in my first post on CFGRID is the addition parameter I tagged on way at the end.

In case you missed it: {myTreeForm:myTree.node}

You only have to specify the form in the bind statement if the element you are binding to is not in the same form as the element that you are binding from.

...Or once again in normal English: You only have to specify the form in the bind expression if the two elements aren't in the same form.

And that's pretty much it.

Related Blog Entries

11 Comments to "Coldfusion 8 Binding a Grid to a Tree"- Add Yours
abul's Gravatar I was following you wanderfull example...

I am not sure why - although i declare all the argument at .cfc file.

Here is my error looks ---

You cannot specify more arguments to a CFC function than it declares.
Error parsing bind cfc:test_site.achowdhury.cf08.artists.components.artists.editArtist({cfgridaction}, {cfgridrow}, {cfgridchanged},{myformTree:mytree.node})

-------
# Posted By abul | 7/31/07 2:00 AM
Gary Gilbert's Gravatar Abul,

Is that bind expression on the onchange attribute or the regular bind attribute? The regular bind attribute (the one to populate the grid) needs the parameters cfgridpage, cfgridpagesize, cfgridsortcolumn, and cfgridsortdirection. If you are using an editable grid then on the onchange attribute of the cfgrid you would use cfgridaction, cfgridrow and cfgridchanged.

But then you wouldn't add the additional parameter of the tree to the onchange event of the grid.

Could you also post the function you are calling?
# Posted By Gary Gilbert | 8/1/07 12:35 PM
Okan's Gravatar I am trying to create a tree grid. I followed this blog and ColdFusion 8 Binding Part 1 &2 tutorials. I get error: Element CFCPATH is undefined in REQUEST.
# Posted By Okan | 12/21/07 1:39 AM
Gary Gilbert's Gravatar @okan,

In my application.cfm I created a request variable called cfcpath which is the dot ddelimited path
to my cfc's. You can remove the #request.cfcpath# in the bind expression and
replace it with the path to the cfc.
# Posted By Gary Gilbert | 12/21/07 1:48 AM
Okan's Gravatar Would you please tell me what #request.approot# value is supposed to be in the CF8 Binding tutorials?

I am trying to get multiple nests in a tree grid and have the nodes populate data as I expand the tree. Is it possible to get a tree grid like http://www.treegrid.com/TreeGrid5_0/Examples/AspNe... using CF8?
# Posted By Okan | 12/22/07 6:15 PM
Gary Gilbert's Gravatar Hi Okan,

Sorry for the confusion. On my local machine the path to my application is http://localhost/cf8 If you want the root of your tree to start somewhere else besides the wwwroot directory you can set a variable in your application.cfm page to point to whatever directory you want to start at. for example <cfset request.approot ='/cf8'> would make the cfdirectory tag get the directories starting in the cf8 directory instead of the wwwroot. I also will reply to your other email, as you have a couple of typo's between your tree and your grid...I should finish the tutorial series :).

As for the tree-grid you point to in the URL you can do that with CF but you will have to use the new EXTJS and code the JS by hand, but you can use CF8 to provide the data no problem
# Posted By Gary Gilbert | 12/22/07 9:17 PM
Wayne's Gravatar Gary, after a couple days I finally got this to work. (Still fairly new to some CF capabilities.) Your concept for combining/binding these two objects is great. It's almost exactly what I was looking for regarding a new project at work. In fact Adobe recommented I check your site. What I need to do now is figure out whether this same thing can be used with database queries versus a "directory and file" widget or cfc. Any ideas to that extent?
By the way, I got it to work on my workstation, but not on my server. I get a blank page with a thin gray bar accross the top. Strange. The server is a multi-server config using IIS, if that makes a difference. In contrast I used the CF internal web server on my workstaion.
Thanks again.
# Posted By Wayne | 8/28/08 7:12 PM
Gary Gilbert's Gravatar Wayne,

What data you provide to the tree shouldn't really matter you just need to make sure that you provide the tree with the data in the format that it expects.

If you think about it the cfdirectory tag returns a query object after querying the file system, no difference really, just make sure you return your results correctly.

Glad it proved useful!
# Posted By Gary Gilbert | 8/29/08 3:41 PM
Keelee's Gravatar Hi,

I'm wondering what are the benefits for binding a grid to a tree? Editable cftree?
# Posted By Keelee | 1/16/09 8:51 PM
Wayne's Gravatar My requirement was to show details of each entry in the tree, and show as much of the tree as possible. So my idea was to have a split display with a tree on the left side and the corresponding detail grid on the right. Kinda like the way Windows explorer works.
# Posted By Wayne | 1/16/09 8:59 PM
Gary Gilbert's Gravatar @Keelee,

The windows explorer example that Wayne describe is a good use case for binding a tree to a grid. The point of this excersise was simply to show that it is possible to bind the two things to each other rather easily.
# Posted By Gary Gilbert | 1/17/09 12:21 PM

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

No recent entries.

Blogroll

An Architect's View
CFSilence
Rey Bango
TalkingTree

Wish List

My Amazon.com Wish List