Bind ExtJs header element with CFGRID result.

ColdFusion 9 Add comments

Before a month I have posted about "Add header in cfgrid in coldfusion 9" where you can add ExtJs component in header to filter CFGRID data. One of my blog read "David" raise that how to bind ExtJs component with CFGRID to filter result.
Here I will try to explain how to bind header element with CFGRID, assuming that you have already read my previous post regarding this topic.
This is little bit tricky to bind with CFC call. We need to create seperate javascript function which will return value selected from extJS element.

In my case I have modifed my CFC to filter artist by state and added state dropdown in CFGRID header.

function getStateValue()
            {
                try
                {    
                    return Ext.ComponentMgr.get('cmbstate').value;
                }
                catch (e)
                {
                    return "";  //return default value in case of error.
                }
            }

getStateValue() function will return selected state value from dropdown. You have to put this code in try catch as first grid load browser will not find cmbstate dropdown as it is not created yet. Now you need to bind this function with cfgrid bind attributes.

<cfform>
            <cfgrid format="html" name="artGrid" pagesize="10" selectmode="row"
                bind="cfc:art.getArtists({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},getStateValue())">
                <cfgridcolumn name="ARTISTID" display="No"/>
                <cfgridcolumn name="FIRSTNAME" header="FIRSTNAME" >
                <cfgridcolumn name="LASTNAME" header="LASTNAME" >
                <cfgridcolumn name="CITY" header="CITY" >
                <cfgridcolumn name="STATE" header="STATE" >
            </cfgrid>
        </cfform>

If you want to pass argument in this javascript function then it will let you single numeric argument only. CFGRID ultimatly creating javascript code which cause issue if you pass multiple argument or string value in it.
Output without filter:

cfgrid output
After filtering by state
cfgrid output 2
Hope this help you...

8 responses to “Bind ExtJs header element with CFGRID result.”

  1. Ads Says:
  2. Michael Says:
    Thanks for your example! Is there any way to take this one step farther and do an onKeyPress on the combobox so that the cfgrid filters as you type? I can get it to work with the Enter key but not on actual keypress.
  3. CVH Says:
    Will this work in CF8?
  4. Pritesh Says:
    Yes binding should work with CF8 as well but you may need to look into getting value from component (ex. Ext.ComponentMgr.get('cmbstate').value). CF9 has higher version of ExtJs which change the syntax.
  5. CVH Says:
    Your right it does work! thanks..

    Tell me what you think about this.. Basically I am making a formulas grid with cfgrid.

    I do all the manipulation by going to the Ext side of the grid. My cfgrid is set to selectmode='edit'. Now any change I make to a cell fires an onchange action by default. But this I do not want. I was wondering if there was a simple clean way to turn off this onchange action that occurs in cfgrid edit mode since I will just do what I want from that point in javascript with the Ext gridEditor object. For now I had to set up a temporary cfc that returns nothing to handle stuff like {cfgridpagesize}, {cfgridaction} etc... I haven't been able to find a simple way to turn this off.. Maybe some knows already?
  6. Pritesh Says:
    I think this is only reason why I am not using edit mode of cfgrid. I don't think is there any way to do without specifying cfc as without it will give runtime error.
  7. CVH Says:
    Ok what about this idea..

    I am wondering if I can somehow embed cfselects into lets say in a new Ext.LayoutDialog. Like within Ext.ContentPanel within the dialog for example;

    centerPanel = new Ext.ContentPanel(etc..)
    centerPanel.setContent('<cfoutput><cfform><cfselect name=\'myselect\' bind=\'cfcs:somecfc\'></cfselect></cfform></cfoutput>'); -> ??

    For use of bindable cfselects -

    any ideas?
  8. Michael Says:
    Please, does anyone know wether it is possible to extent the context menu of the coloums with a filter in Coldfusion like in this example: http://ccinct.com/lab/filter-grid/
  9. Pritesh Says:
    Yes, it will be. I haven't tried it but if you are using latest version of ColdFusion which support ExtJS 3.1.

Leave a Reply



Powered by Mango Blog. Design and Icons by N.Design Studio | Menu Apycom
RSS Feeds