Problem Statement: I have a combo box and the options are populated from a data store. In my case the date store is local data store. Only thing that I want is to make some option selected by default.
This is what my code looks like.
Problem Solution: One of the solution lies around using listeners. After the combo box is rendered, make the default selection. The one that works for me is as given in the code below.
What I have done here is added a listener i.e. afterrender to make the default selection. The code above is self explanatory.
var statusStore = new Ext.data.ArrayStore({
id: 0,
fields: [
'status',
'label'
],
data: [
["", 'All'],
[true, 'Active'],
[false, 'Inactive']
]
});
items: [{
mode:'local',
hideLabel:true,
xtype: 'combo',
id: 'filterStatus',
editable:false,
typeAhead: true,
triggerAction: 'all',
forceSelection: true,
store: statusStore,
displayField: 'label',
width: 110,
ctCls: 'MB'
}]
Problem Solution: One of the solution lies around using listeners. After the combo box is rendered, make the default selection. The one that works for me is as given in the code below.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjARwCfoGBcCCoGi0T0zJtwhMUwiJ8wjeQG1ZvzwkPnDDWkiTlsCXpdwRWCtyCYlnIH77todcoIyEStipe8KEskyuXK_XlWyK21XiCDrUYlXPVs1u9Qsybx99fVVjQ9ZQywGyqy0wSPvOkN/s1600/solution.png)
var statusStore = new Ext.data.ArrayStore({
id: 0,
fields: [
'status',
'label'
],
data: [
["", 'All'],
[true, 'Active'],
[false, 'Inactive']
]
});
items: [{
mode:'local',
hideLabel:true,
xtype: 'combo',
id: 'filterStatus',
editable:false,
typeAhead: true,
triggerAction: 'all',
forceSelection: true,
store: statusStore,
displayField: 'label',
width: 110,
ctCls: 'MB',
listeners:{
afterrender:function(){
this.setValue(true);
this.setRawValue('All');
}
}
}]
What I have done here is added a listener i.e. afterrender to make the default selection. The code above is self explanatory.