123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /*
- * Ext JS Library 3.2.0
- * Copyright(c) 2006-2010 Ext JS, Inc.
- * licensing@extjs.com
- * http://www.extjs.com/license
- * we did some changes based on extjs's code
- */
- Ext.ns('Ext.ux.form');
- Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
- initComponent : function(){
- Ext.ux.form.SearchField.superclass.initComponent.call(this);
- this.on('specialkey', function(f, e){
- if(e.getKey() == e.ENTER){
- this.onTrigger2Click();
- }
- }, this);
- this.addEvents(
- 'beforesearch',
- 'search'
- );
- },
- /*
- * the fields to search, if undefined or null, then use all fields
- */
- //searchFields:{'name':true},
- mode:'remote',
- validationEvent:false,
- validateOnBlur:false,
- trigger1Class:'x-form-clear-trigger',
- trigger2Class:'x-form-search-trigger',
- hideTrigger1:true,
- width:180,
- hasSearch : false,
- paramName : 'query',
- onTrigger1Click : function(){
- if(this.hasSearch){
- this.el.dom.value = '';
- if(false !== this.fireEvent('beforesearch', null, this.store, this)){
- if('local' != this.mode){
- var o = {start: 0};
- if (this.limit) {
- o = {start: 0, limit: this.limit};
- }
- this.store.baseParams = this.store.baseParams || {};
- this.store.baseParams[this.paramName] = '';
- this.store.reload({params:o});
- }else{
- this.store.clearFilter();
- }
- this.fireEvent('search', null, this.store, this);
- }
- this.triggers[0].hide();
- this.hasSearch = false;
- }
- },
- onTrigger2Click : function(){
- var v = this.getRawValue();
- if(v.length < 1){
- this.onTrigger1Click();
- return;
- }
- if(false !== this.fireEvent('beforesearch', v, this.store, this)){
- if('local' != this.mode){
- var o = {start: 0};
- if (this.limit) {
- o = {start: 0, limit: this.limit};
- }
- this.store.baseParams = this.store.baseParams || {};
- this.store.baseParams[this.paramName] = v;
- this.store.reload({params:o});
- }else{
- var er = Ext.escapeRe;
- var reg = new RegExp('^' + er(String(v)), 'i');
- this.store.filterBy(function(rd, id){
- var fields = rd.fields;
- var match = false;
- fields.each(function(it){
- if(!this.searchFields || this.searchFields[it.name]){
- if(reg.test(rd.data[it.name])){
- match = true;
- return false;
- }
- }
- }, this);
- return match;
- }, this);
- }
- this.fireEvent('search', v, this.store, this);
- }
- this.hasSearch = true;
- this.triggers[0].show();
- }
- });
|