PDA

View Full Version : Combo live search with SQL



muceli
30 Apr 2014, 10:50 AM
48874



...
{
xtype: 'panel',
region: 'west',
tbar: [{
xtype: 'combo',
id: 'searchCombo',
store: Ext.create('Ext.data.Store', {
id: 'searchStore',
model: Ext.define("SearchModel", {
extend: 'Ext.data.Model',
fields: ['id', 'name']
})
}),
triggerAction: 'query',
displayField: 'name',
triggerCls: 'x-form-search-trigger',
listConfig: {
loadingText: 'Searching...',
emptyText: 'user not found.',
// Custom rendering template for each item
getInnerTpl: function () {
return '<span>{name}</span>';
}
},
listeners: {
change: function (combo, newValue, oldValue, eOpts) {
if (newValue.trim().length == 3) {
searchUser(newValue); // sql table search
}
}
}
}
}
...


function returnedData(data) { // returned data: [{id: 'us001', name: 'Mücahid DANI?'}]
if (Ext.isArray(data)) {
for (var i = 0; i < data.length; i++) {
searchStore = Ext.data.StoreManager.lookup('searchStore');
searchStore.loadData(data);
}
}
}


data added to combo store but combobox not collapse

Note: sql search with xmpp

muceli
30 Apr 2014, 12:33 PM
I solved the problem



{
xtype: 'combo',
queryMode: 'local', // added
}

function handleSearchUser(data) {
if (Ext.isArray(data)) {
searchStore = Ext.data.StoreManager.lookup('searchStore ');
searchStore.loadData(data);
searchCombo = Ext.getCmp("searchCombo");
searchCombo.expand(); // added
searchStore.clearFilter(); // added
}
}