BAR
BAR

Reputation: 17111

extjs Update when Changing Store Data

I am using the designer my goal is to update a store record that so far has been started by clicking the newBtn. I am trying to do it outside of the function that called it.

If I try clicking the button it works.

./application.js

Ext.Loader.setConfig({
    enabled: true
});

Ext.application({
    name: 'MyApp',

    stores: [
        'MyArrayStore'
    ],

    launch: function() {
        Ext.QuickTips.init();

        var cmp1 = Ext.create('MyApp.view.TradeGrid', {
            renderTo: Ext.getBody()
        });

     cmp1.show();


    //PROBLEM HERE  
    // This actually does something but when maxIndex is printed to the console it = 0
    // Meaning that no data has been loaded to grid
    // Am I wrong thinking it should? As the other file loads two data cells right away

       cmp1.addRecord([]);

    //PROBLEM HERE

./TradeGrid.js

Ext.define('MyApp.view.TradeGrid', {
    extend: 'MyApp.view.ui.TradeGrid',

    initComponent: function() {
        var me = this;


        me.callParent(arguments);

        var button = me.down('button[text=newBtn]');
        button.on('click', me.onSubmitBtnClick, me);

    },

    addRecord: function(myRecordArray) {

            var grid = Ext.getCmp("TradeGrid");  //defined by  -> Property: id 
            var store = grid.getStore();

            var maxIndex = store.getCount();
            console.log(maxIndex);               //maxIndex PRINT to CONSOLE


            var res = store.insert(maxIndex, [["ll", "kk", "00"]]);


            console.log(this);

    },

    onSubmitBtnClick: function() {
        this.addRecord([]);
    }




});

        }
    });

first two data loaded into grid

[
["Ace Supplies", "Emma Knauer", "555-3529"],
["Best Goods", "Joseph Kahn", "555-8797"],

]

Upvotes: 1

Views: 2112

Answers (1)

Andrey Selitsky
Andrey Selitsky

Reputation: 2604

I see that you get grid reference using Ext.getCmp - it means that you hardcoded id of the components. It's not a really good idea, and you'd better try to use itemId. It can lead tom some weird bugs, maybe it is the reason your could is not working. Try to change id to itemId.

Upvotes: 1

Related Questions