PDA

View Full Version : How to Add & Retrieve Phantom Records from a JSON Store?



thedott
5 Aug 2010, 1:27 PM
How do you add and retrieve phantom records from a json store?

Here's how I'm adding records to my store, which appears to work:



var rec = cbEmployee.getStore().getAt(cbEmployee.selectedIndex);

var gridEmployee = Ext.getCmp('IncidentEmployeeGrid');

// Check for existing record ...
if (gridEmployee.getStore().indexOfId(rec.id) == -1)
{
rec = rec.copy();
Ext.data.Record.id(rec);
gridEmployee.getStore().add([rec]);
}

cbEmployee.select(-1);
cbEmployee.reset();Here's how I'm trying to retrieve the phantom records (in a button click event):



var rs = Ext.getCmp('IncidentEmployeeGrid').getStore().getModifiedRecords();Unfortunately, when I firebug the results, I get an empty array. What am I missing?

Thanks!

Condor
6 Aug 2010, 12:19 AM
1. Adding a record doesn't automatically add it to the modified array.
2. You are not setting the id correctly

Use:

rec = rec.copy();
rec.id = Ext.data.Record.id(rec);
gridEmployee.getStore().add(rec);
gridEmployee.getStore().modified.push(rec);

thedott
6 Aug 2010, 6:23 AM
Thank you for the help. I was under the impression from the API that the store had the logic to handle the phantom records on the fly.

Condor
6 Aug 2010, 6:40 AM
I agree. I'll post it as a bug (here (http://www.sencha.com/forum/showthread.php?106428-Adding-phantom-dirty-records-to-a-store-doesn-t-make-them-modified)).