Search code examples
extjsextjs4extjs-mvc

ExtJS4 - how to get parent grid on selectionchange?


I have little experience with ExtJS3 and now starting with version 4.

In my controller, I have this:

init: function ()
{
    this.control({
        "userlist":
        {
            selectionchange: function (view, selected, opts)
            {
                 //get to grid??
            }
        }
    });
}

How can I access the grid that this event happened on, without using id's? I want to enable/disable buttons on the grid toolbar (tbar) if there are items selected, but I don't want to give anything id's (not the bar, not the individual buttons)

EDIT: the solution was to use the refs property in the controller:

refs:
[
    {
        ref: "list",
        selector: "userlist"
    }
],


selectionchange: this.activateTbButtons

activateTbButtons: function (selected, opts)
{
    if (selected.selected.length == 1)
    {
        var tb = this.getList().query("toolbar");
    }
}

Solution

  • EDIT

    I took a look at the docs for the selectionChange event:

    selectionchange( Ext.selection.Model this, Ext.data.Model[] selected, Object eOpts )
    

    The view is not being passed in to the selectionchange handler. An easy way to handle this is to either use Ext.getCmp() or use refs as seen in the docs for Ext.app.Controller:

    http://docs.sencha.com/ext-js/4-0/#!/api/Ext.app.Controller