Search code examples
extjscomboboxstoreextjs4.1

Ext 4.1.1: Add new record to Store


I would like to add records after the initialization of a store.

I tried loadData(), loadRawData(), add() but nothing seams to work.

Here is my jsfiddle: http://jsfiddle.net/charlesbourasseau/zVvLc

Any ideas ?


Solution

  • You need to set queryMode: 'local' in the combo box. Minimal example:

    Ext.onReady(function() {
        var store = Ext.create('Ext.data.Store', {
            alias: 'store.ModeStore',
            autoLoad: false,
            fields: [{
                name: 'mode',
                type: 'string'
            }, {
                name: 'id',
                type: 'string'
            }],
            data: [{
                mode: 'mode1',
                id: 1
            }]
        });
    
        var container = Ext.create('Ext.form.field.ComboBox', {
            renderTo: Ext.getBody(),
            displayField: 'mode',
            valueField: 'mode',
            store: store,
            queryMode: 'local'
        });
    
        store.add({
            mode: 'mode2',
            id: 2
        });
    });