2

I have a question regarding ExtJS controllers. My code:

Ext.define('app.controller.Clients.Clients', {
    extend: 'Ext.app.Controller',
    stores: ['Clients.Clients'],
    models: ['Clients.Clients'],
    views: ['Clients.Clients'],
    init: function() {
        this.control({
            'gridClients button[action=deleteClient]': {
                click: this.onButtonClickDelete
            },
            'gridClients button[action=refreshClients]': {
                click: this.onButtonClickRefresh
            },
            'gridClients button[action=printClients]': {
                click: this.onButtonClickPrint
            }
        })
    },
    onButtonClickDelete: function(button, e, options) {
        alert('DELETE?');
    },
    onButtonClickRefresh: function(button, e, options) {
        alert('REFRESH?');
    },
    onButtonClickPrint: function(button, e, options) {
        alert('PRINT?');
    }
});

I'm going to refer to a grid named 'gridClients', and I'd like to know if there is any way to create a variable inside the driver file...

I'm going to refer to a grid named 'gridClients', and I would like to know if there is any way to create a variable inside the driver file, to refer to that grid.

Example, I would like something similar to:

Var Grid = Ext.ComponentQuery.query (#gridClients) [0];

And use it like this:

OnButtonClickRefresh: function (button, e, options) {
         Grid.getStore (). Load ();
     }

I really do not know where to declare that var...

3 Answers 3

1

In a controller, you are expected to work with the refs. Example:

Ext.define('app.controller.Clients.Clients', {
    extend: 'Ext.app.Controller',
    stores: ['Clients.Clients'],
    models: ['Clients.Clients'],
    views: ['Clients.Clients'],
    init: function() {
        ...
    },
    refs:[{
        ref:'clientsGridExample',
        selector: '#gridClients'
    }],
    OnButtonClickRefresh: function (button, e, options) {
         this // inside a controller, these functions are scoped to controller
             .getClientsGridExample() // refs are automatically converted to getter methods
             .getStore().load(); // Do whatever you want to do
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

Great! It works, thanks for showing me the use of 'refs', after reading the documentation a bit, I understand its use.
1

It's pretty clear, if you check the Ext.app.Controller documentation.

You can set refs in your controller and use generated getter to get the grid you need. For example, if you have ref with value clientsGrid, getter getClientsGrid() will be created by ExtJS.

`

Ext.define('app.controller.Clients.Clients', {
    extend: 'Ext.app.Controller',
    stores: ['Clients.Clients'],
    models: ['Clients.Clients'],
    views: ['Clients.Clients'],

    refs: [
        { ref: 'grid', selector: '#gridClients' }
    ],    

    init: function() {
        this.control({
            'gridClients button[action=deleteClient]': {
                click: this.onButtonClickDelete
            },
            'gridClients button[action=refreshClients]': {
                click: this.onButtonClickRefresh
            },
            'gridClients button[action=printClients]': {
                click: this.onButtonClickPrint
            }
        })
    },
    onButtonClickDelete: function(button, e, options) {
        this.getGrid().doSomething();
    },
    onButtonClickRefresh: function(button, e, options) {
        alert('REFRESH?');
    },
    onButtonClickPrint: function(button, e, options) {
        alert('PRINT?');
    }
});

`

Comments

0

Inside the OnButtonClickRefresh listener you can get the grid like this:

var grid = button.up("grid");

Link to the fiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.