PDA

View Full Version : Implementing autosuggest without proxy



rebeccapeltz
14 Feb 2011, 3:40 PM
I'm implementing an autosuggest, but I can't use the proxy method of passing a search string to the server because I'm in a non-standard environment. What I want to do is capture the keypress and send this off to my datasource and then reload the store that services the combo box, and finally expand the combo box to display what has been returned from the query.
Here's my config, but I'm not seeing it expand. Is there a better way to do this? Should I not be using the ComboBox?

For my default store I'm using an empty array:

var defaultData = [];

var defaultStore = new Ext.data.ArrayStore({
autoDestroy: true,
data: defaultData,
fields: [{
name: 'problemName',
mapping: 'NAME'
}, {
name: 'problemId',
mapping: 'VALUE'
}],
listeners: {
'load': {
fn: function(){
this.sort([{
field: 'problemName',
direction: 'DESC'
}]);
},
options: {
single: true
}
}
}
});


Below is code for handling the key press:



'keypress': function(cb, event){
//alert('keypress')
var searchData = {"SEARCHRESULTS":{"SEARCHINDEX":1,"NOMENCLATURE":[{"VALUE":11605085.000000,"NAME":"Bed sore (707.00)"},{"VALUE":11558688.000000,"NAME":"Cold sore (054.9)"},{"VALUE":11598791.000000,"NAME":"Heel sore (709.9)"},{"VALUE":11614335.000000,"NAME":"Fever sore (054.9)"},{"VALUE":11584877.000000,"NAME":"Mouth sore (528.9)"},{"VALUE":11617553.000000,"NAME":"Sore neck (723.1)"},{"VALUE":11597938.000000,"NAME":"Sore, bed (707.00)"},{"VALUE":11619652.000000,"NAME":"Canker sore (528.2)"},{"VALUE":11600716.000000,"NAME":"Tongue sore (529.6)"},{"VALUE":11647076.000000,"NAME":"Sore throat (462)"}]}};
var data = searchData["SEARCHRESULTS"]["NOMENCLATURE"];
var searchStore = new Ext.data.ArrayStore({
autoLoad: true,
autoDestroy: true,
data: data,
fields: [{
name: 'problemName',
mapping: 'NAME'
}, {
name: 'problemId',
mapping: 'VALUE'
}],
listeners: {
'load': {
fn: function(){
this.sort([{
field: 'problemName',
direction: 'DESC'
}]);
},
options: {
single: true
}
}
}
});
var allRecords = searchStore.getRange();
defaultStore.removeAll();
defaultStore.add(allRecords);
Ext.getCmp('searchComboBox').expand();

},