PDA

View Full Version : Store: remove records and commitChanges



steffenk
1 Sep 2010, 11:49 AM
Hi,

i really wonder about remove method. The only chance to commit removals is to listen to remove event and do a manual Ajax request. Why?

I want remove records without direct commit, and on demand commit all changes. Ok, i use a simple non-restful and no ExtDirect store, but i need ths simple thing.

When i debug the store, i see a removed array - so it was planned?
It would be simple, on remove to add the record to this.removed, and with commitChanges with extra config to send removed too.

Do i miss something?

steffenk
1 Sep 2010, 1:22 PM
my quick and dirty override, still for manual usage:


Ext.override(Ext.data.Store, {
remove : function(record) {
if (Ext.isArray(record)) {
Ext.each(record, function(r) {
this.remove(r);
}, this);
return;
}
var index = this.data.indexOf(record);
if (index > -1) {
record.join(null);
this.data.removeAt(index);
}
if (this.pruneModifiedRecords) {
this.modified.remove(record);
}
if (this.snapshot) {
this.snapshot.remove(record);
}
this.removed.push(record);

if (index > -1) {
this.fireEvent('remove', this, record, index);
}
},

loadRecords : function(o, options, success) {
if (this.isDestroyed === true) {
return;
}
if (!o || success === false) {
if (success !== false) {
this.fireEvent('load', this, [], options);
}
if (options.callback) {
options.callback.call(options.scope || this, [],
options, false, o);
}
return;
}
var r = o.records, t = o.totalRecords || r.length;
if (!options || options.add !== true) {
if (this.pruneModifiedRecords) {
this.modified = [];
this.removed = [];
}
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);
}
this.fireEvent('load', this, r, options);
if (options.callback) {
options.callback.call(options.scope || this, r, options,
true);
}
},

getRemovedRecords : function(){
return this.removed;
}

});