Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extjs combobox model

Tags:

combobox

extjs

Is there a way to bind a store to a ExtJS ComboBox without creating a js model (ExtJS 4.1)?
To populate a users combobox I'll always need to set up the model first? I would like to skip the following code for each combobox:

Ext.define('User',{extend:'Ext.data.Model',idProperty:'Id',fields:['Id','Name']});
like image 329
Diogo Arenhart Avatar asked Feb 21 '23 03:02

Diogo Arenhart


2 Answers

You're right, Neil!
I've found how to use it:

var myStore = Ext.create('Ext.data.Store',{
    fields:['Id','Name'],
    data:[
        {Id:0,Name:'Yes'},
        {Id:1,Name:'No'},
        {Id:2,Name:'Maybe'}
    ]
});

var pnl = Ext.create('Ext.panel.Panel', {
    xtype: 'panel',
    title: 'My Panel',
    items: [{
        id:'cboField1'
        xtype:'combobox',
        fieldLabel:'My Field',
        displayField:'Name',
        valueField:'Id',
        queryMode:'local',
        store: myStore
    }]
});
like image 189
Diogo Arenhart Avatar answered Feb 28 '23 13:02

Diogo Arenhart


If you're using Architect you can specify an array in the store property for the ComboBox. There is no point to create extra stores & models if you just want a static 'Title' ComboBox.

xtype:'combo',
fieldLabel:'Title',
name:'division',
queryMode:'local',
store:['Mr','Mrs','Ms'],
displayField:'title',
autoSelect:true,
forceSelection:true

p.s. In order to change the store property to a local array in Architect you need to select the little icon on the left of the store text and change it to an array instead of a store. enter image description here

like image 43
Sorin Avatar answered Feb 28 '23 11:02

Sorin