5

I have in my base class a combobox, where I only configure the "fields" property. Like this:

items: [
      comboText = Ext.create('Ext.form.ComboBox', {
                width: 150,
                padding: '0 20 0 0',
                displayField: 'label',
                store: Ext.create('Ext.data.Store', {
                    fields: [
                        {type: 'string', name: 'label'},
                        {type: 'string', name: 'fieldName'}
                    ]
                })
            }),
...]

How can I pass only the data property to this combo ? I tried the code below but does not work:

comboTest.store.loadData(value);

where value contains an array like this:

 [
    {"label":"First name", "fieldName":"firstname"},
    {"label":"Birth date", "fieldName":"birthdate"}
 ]

No errors, but the combobox opens nothing.

0

5 Answers 5

10

I got this to work using:

   xtype:'combo',
   fieldLabel:'Division',
   name:'division',
   valueField: 'division',
   queryMode:'local',
   store:['A','B','C'],
   displayField:'division',
   autoSelect:true,
   forceSelection:true

I know this question is really old, but just in case anyone comes looking for an answer that works out of the box; for me this was it.

Sign up to request clarification or add additional context in comments.

1 Comment

I like this solution for its simplicity. A reference to the API manual where this is described: docs.sencha.com/extjs/4.1.3/#!/api/… Look for the store config.
9

Try this config:

       xtype:'combo',
       fieldLabel:'Division',
       name:'division',
       queryMode:'local',
       store:['A','B','C'],
       displayField:'division',
       autoSelect:true,
       forceSelection:true

Another Alternative is listed right in the docs of the ComboBox:

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

    // 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()
    });

Comments

1

valueField is mandatory for combobox. Try setting the valueField in your combobox.

Comments

0

It works:

{
    name: 'sample',
    xtype: 'combobox',
    allowBlank: false,
    emptyText: 'select ...',
    queryMode: 'local',
    itemId: 'sample',
    id: 'sample',
    displayField: 'name',
    valueField: 'name',
    forceSelection:true,
    store: ['B','C', 'A'],
    typeAhead: true
}

Comments

0

instead of using loadData();

comboTest.store.loadData(value);

use loadRawData();

comboTest.store.loadRawData(value);

If confusion try ths fiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.