PDA

View Full Version : getById doesn't return existing record with matching key



Bogdan0x400
24 Feb 2011, 9:14 AM
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?

Bogdan0x400
24 Feb 2011, 9:28 AM
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?

Bogdan0x400
24 Feb 2011, 9:44 AM
I've also tried:

var records = AdditionalGridData.query("iD", CurrentID+"", false, true);
but that also didn't help!

Bogdan0x400
24 Feb 2011, 9:53 AM
Actually, I am inserting a record to the store with the ID that I am searching for:
var r = new Ext.data.Record({SomeText:"some random text"},{iD:CurrentID});
AdditionalGridData.add(r);
This information might be helpful :) .

Bogdan0x400
25 Feb 2011, 1:03 AM
Maybe the idProperty shouldn't be defined directly in the JsonStore config? I don't see it in the list of available configuration options in the help reference.
Or maybe the records should be marked as not dirty after insertion?

Bogdan0x400
25 Feb 2011, 1:30 AM
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) . Now everything works fine.