Ext.define('erp.view.pm.make.SNRangeGrid',{ extend: 'Ext.grid.Panel', requires: ['erp.view.core.plugin.CopyPasteMenu'], alias: 'widget.SNRangeGridPanel', emptyText : $I18N.common.grid.emptyText, columnLines : true, autoScroll : true, id:'grid1', ilid:0, deleteBeforeImport:true, frame:true, store: [], columns: new Array(), bodyStyle:'background-color:#f1f1f1;', selModel: Ext.create('Ext.selection.CheckboxModel',{ headerWidth: 0 }), dockedItems: [{ id : 'pagingtoolbar', xtype: 'erpDatalistToolbar', dock: 'bottom', displayInfo: true }], LastCondition:"", gridcondition:"", GridUtil: Ext.create('erp.util.GridUtil'), BaseUtil: Ext.create('erp.util.BaseUtil'), constructor: function(cfg) { if(cfg) { cfg.plugins = cfg.plugins || [Ext.create('Ext.ux.grid.GridHeaderFilters'), Ext.create('erp.view.core.plugin.CopyPasteMenu')]; Ext.apply(this, cfg); } this.callParent(arguments); }, initComponent : function(){ caller = this.caller || this.BaseUtil.getUrlParam('whoami'); if(!condition){ var urlCondition = this.BaseUtil.getUrlParam('gridCondition'); urlCondition = urlCondition == null || urlCondition == "null" ? "" : urlCondition; gridCondition = (gridCondition == null || gridCondition == "null") ? "" : gridCondition; gridCondition = gridCondition + urlCondition; gridCondition = gridCondition.replace(/IS/g, "="); condition = gridCondition; } this.getCount(caller, condition); this.callParent(arguments); }, getCondition:function(condition){ if(!Ext.isEmpty(this.defaultCondition)) { condition = this.defaultCondition; } condition=!condition?"":condition; if(!Ext.isEmpty(this.filterCondition)) { if(!condition || condition == '' ) { condition = this.filterCondition; } else { condition = '(' + condition + ') AND (' + this.filterCondition + ')'; } } condition =BaseQueryCondition==""?condition:condition+" AND "+BaseQueryCondition; return condition; }, getCount: function(c, d, m){ c = c || caller; d = d || this.getCondition(); var me = this; var f = d; if(!me.filterCondition && !me.searchGrid && !m) {// 大数据如果没有筛选条件 var _f = me._f || getUrlParam('_f'); if(_f == 1) { dataCount = 1000*pageSize;// 直接作1000页数据处理 me.noCount = true; me.getColumnsAndStore(c, d); return; } } Ext.Ajax.request({//拿到grid的数据总数count url : basePath + 'common/datalistCount.action', params: { caller: c, condition: f }, method : 'post', callback : function(options,success,response){ var res = new Ext.decode(response.responseText); if(res.exception || res.exceptionInfo){ showError(res.exceptionInfo); return; } dataCount = res.count; me.getColumnsAndStore(c, d); } }); }, listeners: { 'headerfiltersapply': function(grid, filters) { if(this.allowFilter){ var condition = null; for(var fn in filters){ var value = filters[fn],f = grid.getHeaderFilterField(fn); if(!Ext.isEmpty(value)){ if(f.filtertype) { if (f.filtertype == 'numberfield') { value = fn + "=" + value + " "; } } else { if(Ext.isDate(value)){ value = Ext.Date.toString(value); value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' "; } else { var exp_t = /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/, exp_d = /^(\d{4})\-(\d{2})\-(\d{2})$/; if(exp_d.test(value)){ value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' "; } else if(exp_t.test(value)){ value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value.substr(0, 10) + "' "; } else{ if(!f.autoDim) { value = fn + " LIKE '" + value + "%' "; } else { value = fn + " LIKE '%" + value + "%' "; } } } } if(condition == null){ condition = value; } else { condition = condition + " AND " + value; } } } this.filterCondition = condition; page = 1; this.getCount(caller,""); } else { this.allowFilter = true; } return false; } }, getColumnsAndStore: function(caller, d, g, s){ var me = this; d = d || this.getCondition(); g = g || page; s = s || pageSize; me.gridcondition=condition; me.BaseUtil.getActiveTab().setLoading(true); Ext.Ajax.request({//拿到grid的columns url : basePath + 'common/datalist.action', params: { caller: caller, condition: condition, page: g, pageSize: s, _noc:1 }, method : 'post', callback : function(options,success,response){ me.BaseUtil.getActiveTab().setLoading(false); var res = new Ext.decode(response.responseText); if(res.exception || res.exceptionInfo){ showError(res.exceptionInfo); return; } var data = res.data != null ? Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']')) : [];//一定要去掉多余逗号,ie对此很敏感 if(me.columns && me.columns.length > 2){ me.store.loadData(data); }else { var store = Ext.create('Ext.data.Store', { fields: res.fields, data: data }); Ext.getCmp('grid1').reconfigure(store, res.columns); me.down('erpDatalistToolbar').afterOnLoad(page); } } }); }, });