3
votes

I have the following controller in ExtJs:

Ext.define('FileBrowser.controller.BrowserController', {
    extend: 'Ext.app.Controller',
    views: ['browser.tree_dir', 'browser.grid_file'],
    stores: ['store_dir', 'store_file'],

    init: function () {
        this.control({
            'window > tree_dir': {
                itemclick: {
                    fn: function (view, record, item, index, event) {
                        if (record.isLeaf() == false) {
                            Ext.getStore('store_file').load({
                                params: {
                                    dir: record.data.id
                                }
                            });
                            var parentOfCurrentFiles = record.data.id
                            nodeId = record.data.id;
                            htmlId = item.id;
                            var grid_view = this.getView('browser.grid_file');
                            var grid_view_v = grid_view.getView();
                            grid_view_v.refresh();
                        }

                    }

                }
            }
        });
    },
    onPanelRendered: function () {
        console.log('The panel was rendered');
    }
});

If you notice under 'itemclick' I am trying to refresh one of my views, my approach is not working. Can anyone explain to me how I can refresh the view? Thank you.

2

2 Answers

2
votes

Replace var grid_view= this.getView('browser.grid_file'); with var grid_view= this.getView('browser.grid_file').create(); to get a real instance (as I already told you, getView() only return the view config, not a instance!) or if you have already created that grid and only one instance exist use the xtype along with a component query to receive it var grid_view=Ext.ComponentQuery('grid_file')[0]

Now to the refresh()

Basically you never need to call this method cause your grid is bound to a store and any change made on this store is directly reflected to your grid.

I would also recommend you to store view instances when creating them instead of using queries or directly use the ref property and let ExtJS do the work for you. The last one will the best solution you I guess... Take a look at ref's within the API examples and give it a try.

0
votes

So what you are trying to do is, load the store and have the data reflect once you refresh the grid_view...? In that case, you haven't done a setStore() to the grid, or if you have done that elsewhere, you are't doing a setData() to the store. Also you should call the refresh on the grid.