View Full Version : Store.getModifiedRecords

2 Nov 2009, 1:01 PM
Should the following code work? I'm creating a new record and inserting into a JSONStore. I can use FireBug and see the record dirty = true phantom = true. When I call .getModifiedRecords() I always get an empty array.

var r = new MyRecord({"fieldname":"This is a test"});

3 Jan 2010, 10:37 PM
I'm having the a similar problem. I would like the record to be marked as modified when the insert happens and I can't figure out how to do this. Does anyone have any tips to make the insert or add of a record cause the record to be modified?

I just found Record.markDirty() which causes the record to look dirty in the grid but it's still not being added to getModifiedRecords(). Why?

Chief Vas
4 Feb 2010, 8:44 AM
Well this took some head scratching and poking in the source code. From what I could decipher, this.modified was not being created/filled for the added record but was if I edited/modified an existing record in the grid. Looking to see where and how this.modified came from I came across this comment

"Store#add will call this automatically if a Writer is set"

at the code for the createRecord function in the source for the store. createRecord looked to be the only thing that put something into this.modified using the line:

"this.modified.push(rs[i]); // <-- add to modified"

Hummmm, so I created a dummy writer and added it to the config for the store.

var dummyWriter = new Ext.data.JsonWriter();

var myStore = new Ext.data.GroupingStore({
writer: dummyWriter

and now my added records get marked as dirty in the grid along with any edited ones and both added and edited records get returned when calling getModifiedRecords() for the store.