Bogdan Verbenets
Bogdan Verbenets

Reputation: 26942

Ext.data.Store.getById failed

I have a store which is defined something like this:

var AdditionalGridData = new Ext.data.JsonStore(
                {                       root: "result",
                    data: { result: Ext.decode(this.Data.AdditionalGridData) },
                    idProperty: 'iD',
                    fields: [
                            { name: "iD", type: "int", allowBlank: false }, //must match selected row's primary key
                            {name: "SomeText", type: "string" }
                        ]
                });

So there is a time when I want to get an existing record by it's ID value. I call getById and it returns undefined. The store really contains the record that I am searching. Why could it not return my record? Read somewhere on the forums that: you need to pass record id (f.e. "ext-record-1") to Store.getById instead of your data ID (f.e. "1"); Is this correct? Where do I get that record id?

Upvotes: 1

Views: 3889

Answers (2)

Bogdan Verbenets
Bogdan Verbenets

Reputation: 26942

I was inserting the records incorrectly. I was inserting them like .add({ContactName:"aaa"},{ContactID:1}), and should have done it like .add({ContactName:"aaa"}, 1);

Upvotes: 2

mikec
mikec

Reputation: 3673

Try this:

var additionalDataRecord = Ext.data.Record.create([
    {name: 'iD', type: 'int', allowBlank: false},
    {name: 'someText', type: 'string'}
]);

var additionalDataReader = new Ext.data.JsonReader({
    root: 'result',
    id: 'iD'
}, additionalDataRecord);

then in your data store declaration, specify

reader: additionalDataReader

Upvotes: 1

Related Questions