Filling Extjs Combobox with static data
Asked Answered
T

5

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.

Turnage answered 30/10, 2012 at 15:32 Comment(0)
O
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.

Overeager answered 11/4, 2014 at 14:48 Comment(1)
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.Verger
T
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()
    });
Transistor answered 30/10, 2012 at 17:11 Comment(0)
W
1

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

Walkup answered 9/12, 2013 at 19:28 Comment(0)
T
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
}
Transistorize answered 3/11, 2018 at 12:7 Comment(0)
N
0

instead of using loadData();

comboTest.store.loadData(value);

use loadRawData();

comboTest.store.loadRawData(value);

If confusion try ths fiddle

Neustria answered 5/11, 2018 at 8:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.