PDA

View Full Version : Filtering a Combo's store, but the list won't update



ZachG
25 Jun 2010, 6:10 PM
I want to load a Combo's store, filter it, then have the drop down list be reflective of that filtering. I can't figure out exactly where the combo's this.innerList gets populated, but I've been able to look at the store before I click on the list and see that the store was correctly filtered. Its confusing because the store is changed, but the list still contains everything that the store originally did.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<HTML>
<HEAD>
<LINK type="text/css" rel="stylesheet" href="scripts/extjs/resources/css/ext-all.css" />
<LINK type="text/css" rel="stylesheet" href="scripts/extjs/resources/css/xtheme-blue.css" />
<LINK type="text/css" rel="stylesheet" href="styles/layouts.css" />
<SCRIPT type="text/javascript" src="scripts/extjs/adapter/ext/ext-base.js"></SCRIPT>
<SCRIPT type="text/javascript" src="scripts/extjs/ext-all-debug.js"></SCRIPT>
</HEAD>
<BODY>
<DIV id="combo-container"></DIV>
<SCRIPT type="text/javascript">

Ext.onReady(function() {

new Ext.Panel({
layout:"form",
width:500,
items:[
new Ext.form.ComboBox({
id:"my-combo",
fieldLabel:"Test",
mode:"local",
triggerAction:"all",
forceSelection:true,
displayField:"myName",
valueField:"myID",
store:new Ext.data.JsonStore({
fields:[
"myID",
"myName",
"myGroup"
]
}),
disabled:true
})
],
renderTo:"combo-container"
});

});

function loadData() {
var combo = Ext.getCmp("my-combo");
var store = combo.getStore();
store.loadData([
{
myID:1,
myName:"Zach",
myGroup:"School"
},
{
myID:2,
myName:"Stephanie",
myGroup:"Tanner"
},
{
myID:3,
myName:"Alex",
myGroup:"Schools"
}
]);
store.filter("myGroup", "School");
combo.enable();
}

</SCRIPT>
<A href="javascript:loadData();">Load Data</A>
</BODY>
</HTML>
Click the link, then click on the combo's list. You'll see that it contains records for Zach, Stephanie, and Alex, even though after the filter the store's this.data.items only contains Zach and Alex. I've tried this in both Ext 3.0 and 3.2 with the same result.

Animal
25 Jun 2010, 10:24 PM
triggerAction: 'all'

It clears filters.

ZachG
26 Jun 2010, 4:51 AM
When this.triggerAction != "all", it does this.doQuery(this.getRawValue()). Since I have a local store and forceAll in doQuery will be undefined, it does this.store.filter(this.displayField, q). I don't see any way in the source code that I can get around that second filtering.

I guess the only way that I can get it to work is if before I call store.loadData, I filter the incoming data myself and remove all records that don't contain "School" for their myGroup field.

Animal
26 Jun 2010, 5:30 AM
You can configure it editable: false and then you don't need triggerAction: 'all' because it won't get filtered by typing.