Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create two combobox from one store in extjs?

Tags:

extjs

extjs4.1

How can I add two comboboxes from one store store have type field witch values can be 1, 2 and 3 I want records with type 1 and 2 in first combobox and 2 and 3 in second.

My ComboBox:

Ext.define('Exp.view.settings.servers.ComboBox', {
    extend: 'Ext.form.ComboBox',
    alias : 'widget.server_combobox',

    xtype: 'combobox',
    displayField: 'name',
    valueField: 'id',
    name: 'server',
    store: 'Servers'
});

Store: (just example data from server with json reader)

Ext.define('Exp.store.Servers', {
    extend: 'Ext.data.Store',
    model: 'Exp.model.Server',

    autoLoad: true,
    autoSync: true,

    data: [{
        id: 1,
        name: 'Server 1',
        type: 1
    },{
        id: 2,
        name: 'Server 2',
        type: 3
    },{
        id: 3,
        name: 'Server 3',
        type: 2
    }]
});

If I go with store filter both comboboxes goes filtered. For now I created two stores but that means two ajax calls to server and I don't really like that.

like image 918
Vytautas Avatar asked May 23 '12 06:05

Vytautas


Video Answer


2 Answers

The answer is no, you can not. If you need to have two different sets of data from the same store to be reflected in any two UI elements at the same time (two grids or two combos or whatever) you need to create a copy of your store.

You can either clone it or even create more simple model (comboboxes need just value and name for example) but there is no way around it.

like image 180
sha Avatar answered Oct 11 '22 15:10

sha


I think filter will be cleanest way. it's just local example. Didn't used app structure. http://jsfiddle.net/ssxenon01/WpZMU/

like image 33
XenoN Avatar answered Oct 11 '22 17:10

XenoN