PDA

View Full Version : Combobox with json filter problem



Alessandro24
1 Sep 2010, 12:05 PM
Hello,

i'm struggeling with the combobox and a json data store. I'm able to connect a json file to a combobox, and when i open the combobox, i see all the items. But now my problem, when I type something in the combobox, he is always selecting the first item in the list. it looks like, he is not filtering the list based on what I enter in the combobox.

This is my code :



<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
var combo = new Ext.form.ComboBox({
store: new Ext.data.JsonStore({
url: 'dummy.json',
root: 'items',
fields: ['name', 'code']
}),
displayField: 'name',
valueField: 'code',
typeAhead: true,
mode: 'remote',
minChars: 1,
forceSelection: true,
triggerAction: 'all',
emptyText: 'Select an item...',
selectOnFocus: true
},
applyTo: 'dummy-combo'
});
});
</script>

<body>

<input type="text" id="dummy-combo" size="40"/>

</body>
</html>



anybody sees what i'm doing wrong?

Alessandro

Animal
1 Sep 2010, 1:44 PM
You can't use mode: 'remote' with fixed dummy data.

Obviously, mode: 'remote' must only send back records which match the typed string.

If it's fixed data, autoLoad the store, and use mode: 'local'

Alessandro24
1 Sep 2010, 10:19 PM
Thanks,

you where right, i had to set mode: 'local'. The thing is, i tried before, but than the box was empty. The trick is, to say to the datastore, autoload: 'true':

so this is working :



<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();

var combo = new Ext.form.ComboBox({
store: new Ext.data.JsonStore({
url: 'dummy.json',
root: 'items',
autoLoad: true,
fields: ['name', 'code']
}),
displayField: 'name',
valueField: 'code',
typeAhead: true,
mode: 'local',
minChars: 1,
forceSelection: true,
triggerAction: 'all',
emptyText: 'Select an item...',
selectOnFocus: true,
applyTo: 'dummy-combo'});
});
</script>


thanks for helping me