Question

Is there any possible to bind the EXTJS combobox with SOQL Query results directly

Était-ce utile?

La solution

EXTJS Combobox gets values from Ext.data.Store that can be populated by ajax creating a visualforce page that return JSON with the results of your SOQL query (slow). Or it can be populated using a JS Remoting function call (fast), just adding values to the store asynchronously.

It would be something like this (code not tested, just illustrative):

// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
    fields: ['abbr', 'name'],
    data : []
});

// you can use promises to show a loader for the combo box
var statesLoaded = $.Deferred();

Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.PremadeClassWithSOQL.getStates}',
            function(resultInJSON){
               states.add(JSON.parse(resultInJSON));
               statesLoaded.done();
            }
        );

// when promise ready
$.when(statesLoaded){
  // Create the combo box, attached to the states data store
  Ext.create('Ext.form.ComboBox', {
    fieldLabel: 'Choose State',
    store: states,
    queryMode: 'local',
    displayField: 'name',
    valueField: 'abbr',
    renderTo: Ext.getBody()
  });
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top