Skip to content

Instantly share code, notes, and snippets.

@christocracy
Created January 29, 2011 02:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save christocracy/801454 to your computer and use it in GitHub Desktop.
/**
* Loads an array of {@Ext.data.Model model} instances into the store, fires the datachanged event. This should only usually
* be called internally when loading from the {@link Ext.data.Proxy Proxy}, when adding records manually use {@link #add} instead
* @param {Array} records The array of records to load
* @param {Boolean} add True to add these records to the existing records, false to remove the Store's existing records first
*/
loadRecords: function(records, add) {
if (!add) {
this.data.clear();
}
this.data.addAll(records);
//FIXME: this is not a good solution. Ed Spencer is totally responsible for this and should be forced to fix it immediately.
for (var i = 0, length = records.length; i < length; i++) {
records[i].needsAdd = false;
records[i].join(this);
}
/*
* this rather inelegant suspension and resumption of events is required because both the filter and sort functions
* fire an additional datachanged event, which is not wanted. Ideally we would do this a different way. The first
* datachanged event is fired by the call to this.add, above.
*/
this.suspendEvents();
if (this.filterOnLoad && !this.remoteFilter) {
this.filter();
}
if (this.sortOnLoad && !this.remoteSort) {
this.sort();
}
this.resumeEvents();
this.fireEvent('datachanged', this, records);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment