PDA

View Full Version : Possible Store loadData append bug?



Keylan
2 Aug 2010, 2:36 PM
From my understanding, setting the second argument (append) of store.loadData to true will add records to the store instead of replacing the entire data set. However, the definition notates:

"Note: that Records in a Store are keyed by their id (http://www.sencha.com/deploy/dev/docs/output/Ext.data.Record.html#Ext.data.Record-id), so added Records with ids which are already present in the Store will replace existing Records."

I am attempting to load one record through this method which already exists in the store, with a desired result of updating that record with the new information passed. Instead, I am getting a few errors.

It seems that the record is correctly updated, but the number of records in the store is not properly updated - which causes the refresh of that row to fail.

It seems that in the store's loadRecords method the stores totalLength is updated regardless of whether or not the new record is truly added to the store, or just replacing an already existing record:


if(!options || options.add !== true){
if(this.pruneModifiedRecords){
this.modified = [];
}
for(var i = 0, len = r.length; i < len; i++){
r[i].join(this);
}
if(this.snapshot){
this.data = this.snapshot;
delete this.snapshot;
}
this.clearData();
this.data.addAll(r);
this.totalLength = t;
this.applySort();
this.fireEvent('datachanged', this);
}else{
this.totalLength = Math.max(t, this.data.length+r.length);
this.add(r);
}Am I using this functionality incorrectly?
Has someone else managed to use load or loadData to replace an existing record?
Is this truly a bug?

Thanks for any responses!

Condor
2 Aug 2010, 11:44 PM
The API docs are a bit confusing. You can't use add:true to replace existing records. It doesn't update the internal MixedCollection correctly and it doesn't fire the correct events to update linked components.

Keylan
3 Aug 2010, 6:21 AM
Thanks for the reply Condor. That is quite confusing, considering the API docs specifically state that you can use add:true to replace existing records. :)

The good news is that I did find this thread (http://www.sencha.com/forum/showthread.php?100632-FIXED-1015-store.loadData(-myData-true)-causes-render-bug-if-records-are-replaced) describing the same exact issue which seems to be fixed in SVN. Seems like I have some waiting to do. :-?