Created
September 6, 2012 19:47
-
-
Save aghuddleston/3659866 to your computer and use it in GitHub Desktop.
Ext JS 4 Remote To Local Hybrid ComboBox Plugin
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
/** | |
This combo functions as a remote-local ExtJS combo hybrid. It starts out | |
as a remote combo so that nothing is loaded until the trigger button is clicked | |
or the user starts typing in the combobox. Once the data is loaded, it switches | |
to local mode so that no more queries are made to the server. It therefore | |
assumes that all data is loaded on the first load request. It also shows the | |
loading UI when data is being loaded since it starts out as 'remote'. | |
*/ | |
Ext.define("Ext.ux.form.field.RemoteToLocalComboBox", { | |
extend: 'Ext.AbstractPlugin', | |
alias: 'plugin.remotetolocalcombo', | |
init: function(combo) { | |
this.combo = combo; | |
combo.queryMode = 'remote'; | |
this.callParent(); | |
combo.getStore().on('load', this.onComboStoreLoad, this); | |
}, | |
onComboStoreLoad : function () { | |
Ext.apply(this.combo, {queryMode: 'local'}); | |
} | |
}); |
This is an awesome solution to a common need. Works on 4.2.2, too.
I think it's useful to set combo.minChars = 0 on init() because the default for queryMode remote is 4 chars instead of the default of 0 for local.
Also, I would change line 18 to combo.mon(combo.getStore(), ...
So when the combo is destroyed the listener is, too.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works a little differently. See comments at http://ahlearns.wordpress.com/2012/09/06/ext-js-4-a-remote-to-local-querymode-hybrid-combobox/