1. #1
    Sencha User
    Join Date
    Mar 2012
    Location
    Jakarta
    Posts
    30
    Vote Rating
    2
    arivwd is on a distinguished road

      0  

    Default Confuse about "getById" in store

    Confuse about "getById" in store


    First i set this model...

    Code:
    new Ext.define('GridModel_Popup_VendorList', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id_vendor', type: 'string'},
            {name: 'kd_vendor', type: 'string'},
            {name: 'nm_vendor', type: 'string'},
            {name: 'alamat_vendor', type: 'string'},
            {name: 'ket_vendor', type: 'string'}
        ],
        idProperty: 'MasterVendor'
    });
    then this store...

    Code:
    store4 = new Ext.create('Ext.data.Store', {
        model: 'GridModel_Popup_VendorList',
        remoteSort: false,
        proxy: {
            // load using script tags for cross domain, if the data in on the same domain as
            // this page, an HttpProxy would be better
            type: 'ajax',
            url: '/master_vendor/master_vendor/data/1',
            reader: {
                type: 'json',
                root: 'dataRecords',
                totalProperty: 'dataRows'
            },
            // sends single sort as multi parameter
            simpleSortMode: true
        },
        sorters: [{
            property: 'nm_vendor',
            direction: 'ASC'
        }]
    });
    and then in Grid i set this listener...

    Code:
    listeners: {
        added: function() {
        console.log( store4 );
        console.log( store4.getById('id_vendor', 'VDR120613161701') );
        }
    }
    the store4 loaded perfectly (first console.log display it) and the record (with 'id_vendor' = 'VDR120613161701') is there.
    but the second console.log result is always "null".

    what should i do to get that record? what "id" is exactly i have to write in getById()?
    i think that this is the basic concept of store that newbie should know.

  2. #2
    Sencha User
    Join Date
    May 2011
    Location
    Ukraine, Rivne
    Posts
    250
    Vote Rating
    42
    redraid has a spectacular aura about redraid has a spectacular aura about redraid has a spectacular aura about

      0  

    Default


    You model configured with idProperty: 'MasterVendor' but 'MasterVendor' field not defined.
    Store method getById has one parameter "id" (store.getById(1) - return record with id = 1 where id = field with name 'id' or configured by idProperty), to find record by other field use store.find('id_vendor', 'VDR120613161701').
    PS.
    getById method ignore store filters
    //wbr

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Location
    Jakarta
    Posts
    30
    Vote Rating
    2
    arivwd is on a distinguished road

      0  

    Default [RESOLVED] Confuse about "getById" in store

    [RESOLVED] Confuse about "getById" in store


    Quote Originally Posted by redraid View Post
    You model configured with idProperty: 'MasterVendor' but 'MasterVendor' field not defined.
    Store method getById has one parameter "id" (store.getById(1) - return record with id = 1 where id = field with name 'id' OR configured by idProperty), to find record by other field use store.find('id_vendor', 'VDR120613161701').
    PS.
    getById method ignore store filters
    //wbr

    I've changed "idProperty" in model to "id_vendor", still the second console.log result is "null".
    But then i've moved the listeners from the Grid to the store4... and record result shown.

    Code:
    store4 = new Ext.create('Ext.data.Store', {
        model: 'GridModel_Popup_VendorList',
        remoteSort: false,
        proxy: {
            // load using script tags for cross domain, if the data in on the same domain as
            // this page, an HttpProxy would be better
            type: 'ajax',
            url: '/master_vendor/master_vendor/data/1',
            reader: {
                type: 'json',
                root: 'dataRecords',
                totalProperty: 'dataRows'
            },
            // sends single sort as multi parameter
            simpleSortMode: true
        },
        listeners: {
            load: function() {
                console.log( store4 );
                console.log( store4.getById('id_vendor', 'VDR120613161701') );
            }
        }
        sorters: [{
            property: 'nm_vendor',
            direction: 'ASC'
        }]
    });
    From now, whenever i want to modify records before it display, i'm gonna create "load" listener in store.
    Thanks...

  4. #4
    Ext JS Premium Member
    Join Date
    Feb 2009
    Posts
    449
    Vote Rating
    5
    Jangla is on a distinguished road

      0  

    Default


    Pretty sure this behaviour is a bug. In Ext 3 & 4 I have the exact same grid with the same stores (obviously Ext 4 has slight code change due to proxy changes).

    In Ext 3 getById will get by the value of the id field in the store.
    In Ext 4 it will get by the numerical order of the record in the store - the same functionality as getAt

Thread Participants: 2