Skip to content

Instantly share code, notes, and snippets.

@aghuddleston
Created September 6, 2012 19:47
Show Gist options
  • Save aghuddleston/3659866 to your computer and use it in GitHub Desktop.
Save aghuddleston/3659866 to your computer and use it in GitHub Desktop.
Ext JS 4 Remote To Local Hybrid ComboBox Plugin
/**
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'});
}
});
@aghuddleston
Copy link
Author

@mcouillard
Copy link

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