PDA

View Full Version : How to differentiate b/w new records and updated records in a grid??



soumyanara
24 Feb 2011, 7:00 AM
Hi,

I am using a editor grid panel. I am getting the modified recodes with this code

var modifiedRecords = grid.getStore().getModifiedRecords();

Now modifiedRecords will have all the modified and newly inserted records, how can I differentiate between newly inserted record and modified existing record.

Thank in Advance,

Condor
24 Feb 2011, 7:18 AM
Created records have a 'phantom' property set to true.

soumyanara
24 Feb 2011, 7:45 AM
I am using var dsModel = Ext.data.Record.create(..) method to create a record and inserting as grid.getStore().insert(..)

How can I get the phantom property for a newly created record? I am building an xml file with the new and modified data and sending it to webservice to store the data in the db.

Condor
24 Feb 2011, 7:48 AM
var created = [], updated = [];
Ext.each(grid.getStore().getModifiedRecords(), function(r){
if (r.phantom) {
created.push(r);
} else {
updated.push(r);
}
});

soumyanara
24 Feb 2011, 7:59 AM
Thanks a lot :)

soumyanara
24 Feb 2011, 11:43 PM
Hi,
I tried the above code. But "r.phanom " is always returning true.

Thanks in advance

Condor
25 Feb 2011, 12:04 AM
This only works if you use an idProperty in your reader.

soumyanara
25 Feb 2011, 12:32 AM
I am using id property in my xmlreader. But still r.phantom is returning true for both updating and adding new record

Condor
25 Feb 2011, 12:35 AM
Are you sure your idProperty (or id or idPath) is referencing a unique attribute/element in your XML?

soumyanara
25 Feb 2011, 1:26 AM
I am sure the ids' are unique

soumyanara
25 Feb 2011, 1:39 AM
This is my xml:

<code>
<company name="xyz">
<category type="" url="" username="" pwd="" />
<category type="" url="" username="" pwd="" />
<category type="" url="" username="" pwd="" />
<category type="" url="" username="" pwd="" />
<category type="" url="" username="" pwd="" />
<category type="x" url="http://www.xxx.com/" username="" pwd="" />
<category type="y" url="http://www.x.aspx" username="" pwd="" />
<category type="" url="" username="" pwd="" />
<category type="" url="" username="" pwd="" />
<category type="" url="" username="" pwd="" />
<category type="" url="" username="" pwd="" />
<category type="" url="" username="" pwd="" />
</company>
</code>

This is the code I hav written in Extjs:
<code>
for(){
arr.push({ name: "url-" + cattype, id:"url"+i ,mapping: 'category[@type="' + type_category + '"]@url' });
arr.push({ name: "usn-" + cattype, id:"usn"+i , mapping: 'category[@type="' + type_category + '"]@username' });
arr.push({ name: "pwd-" + cattype, id:"pwd"+i , mapping: 'category[@type="' + type_category + '"]@pwd' });
}

var wellStore = new Ext.data.Store({
url: '',
autoLoad: true,
reader: new Ext.data.XmlReader({ record: 'company', id: 'id' }, arr)
});
</code>

This is the way I have done. What is to be done for making phantom work???

Thanks in advance