Last active
December 11, 2015 08:29
-
-
Save chrif/4573772 to your computer and use it in GitHub Desktop.
ExtJS 4.1.1a override to clone all combo stores by default
http://stackoverflow.com/questions/12620424/extjs-4-cloning-stores
http://stackoverflow.com/questions/10714876/how-can-i-create-two-combobox-from-one-store-in-extjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.override(Ext.data.Store, { | |
constructor: function(config) { | |
this.initConfig(config); | |
this.callParent(arguments); | |
this.addEvents( | |
/** | |
* @event clone | |
* Fires when a store is cloned | |
* @param {Ext.data.Store} this | |
* @param {Ext.data.Store} clone The new clone | |
*/ | |
'clone' | |
); | |
}, | |
/** | |
* @param preserveLocalCache Preserve local cache of records | |
* @param cloneRecords If preserveLocalCache is true, also clone local cache of records | |
* @return {Ext.data.Store} | |
*/ | |
clone: function(preserveLocalCache, cloneRecords) { | |
var localCache = this.snapshot || this.data, | |
config = this.getInitialConfig(), | |
clone, | |
records = []; | |
if (preserveLocalCache) { | |
if (cloneRecords) { | |
localCache.each(function(record) { | |
records.push(record.copy()); | |
}); | |
config.data = records; | |
} else { | |
config.data = localCache.items; | |
} | |
} | |
clone = new this.self(config); | |
this.fireEvent('clone', this, clone); | |
return clone; | |
} | |
}); | |
Ext.override(Ext.form.field.ComboBox, { | |
/** | |
* @cfg {Boolean} cloneStore | |
* Whether to clone the store instance passed in the config | |
*/ | |
cloneStore: false, | |
initComponent: function() { | |
var store = this.store, | |
preserveLocalCache = this.queryMode == 'local'; | |
if (Ext.isString(store)) { | |
store = Ext.data.StoreManager.get(store); | |
} | |
if (this.cloneStore && store instanceof Ext.data.Store) { | |
this.store = store.clone(preserveLocalCache); | |
} | |
this.callParent(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful! Good job. :_)