Ok, now I have implemented search panel by changing SearchField.js like this
Code:
Ext.ns('Ext.ux.form');
Ext.ux.form.SearchField = function(config, dataView) {
// call parent constructor
this.dataview = dataView;
Ext.ux.form.SearchField.superclass.constructor.call(this, config);
};
Ext.extend(Ext.ux.form.SearchField, Ext.form.TwinTriggerField, {
initComponent : function(){
if (!this.store.baseParams)
{
this.store.baseParams = {};
}
Ext.ux.form.SearchField.superclass.initComponent.call(this);
this.on('specialkey', function(f, e){
if(e.getKey() == e.ENTER){
this.onTrigger2Click();
}
}, this);
},
validationEvent:false,
validateOnBlur:false,
trigger1Class:'x-form-clear-trigger',
trigger2Class:'x-form-search-trigger',
hideTrigger1:false,
width:180,
hasSearch : false,
paramName : 'query',
onTrigger1Click : function(){
if(this.hasSearch){
this.setRawValue('');
this.store.baseParams[this.paramName] = '';
this.el.dom.value = '';
this.hasSearch = false;
this.dataview.deferEmptyText = true;
this.dataview.emptyText = '';
this.store.removeAll();
this.focus();
}
else
{
this.setRawValue('');
this.el.dom.value = '';
this.dataview.deferEmptyText = true;
this.dataview.emptyText = '';
}
},
onTrigger2Click : function(){
var v = this.getRawValue();
if(v.length < 1){
this.onTrigger1Click();
return;
}
var o = {start: 0};
this.store.baseParams = this.store.baseParams || {};
this.store.baseParams[this.paramName] = v;
this.store.reload({params:o});
this.hasSearch = true;
this.dataview.deferEmptyText = false;
this.dataview.emptyText = 'No result to display';
}
});
dataView and store is sent from another js that create search panel
Code:
var dataView = new Ext.DataView({
tpl: resultTpl,
id : 'search-data-view',
store: ds,
loadingText : 'Searching...',
itemSelector: 'div.search-item'
});
var panel = new Ext.Panel({
applyTo: 'search-panel',
title:'Forum Search',
height:300,
autoScroll:true,
items: dataView,
tbar: [
'Search: ', ' ',
new Ext.ux.form.SearchField({
store: ds,
width:320
}, dataView)
]
});
Please see on onTrigger1Click and onTrigger2Click function in SearchField.js.
If x button (trigger1) is clicked, I using
Code:
this.dataview.deferEmptyText = true;
this.dataview.emptyText = '';
If search button (trigger2) is clicked, I using
Code:
this.dataview.deferEmptyText = false;
this.dataview.emptyText = 'No result to display';
It work! What do you think of this code?