| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- Ext.require([
- 'erp.util.*'
- ]);
- Ext.define('erp.view.common.datalist.GridPanel',{
- extend: 'Ext.grid.Panel',
- requires: ['erp.view.core.plugin.CopyPasteMenu'],
- alias: 'widget.erpDatalistGridPanel',
- layout : 'fit',
- id: 'grid',
- emptyText : '无数据',
- columnLines : true,
- autoScroll : 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
- }],
- plugins: [Ext.create('Ext.ux.grid.GridHeaderFilters'), Ext.create('erp.view.core.plugin.CopyPasteMenu')],
- BaseUtil: Ext.create('erp.util.BaseUtil'),
- GridUtil: Ext.create('erp.util.GridUtil'),
- RenderUtil:Ext.create('erp.util.RenderUtil'),
- autoQuery: true,
- initComponent : function(){
- condition = this.BaseUtil.getUrlParam('urlcondition');
- condition = (condition == null) ? "" : condition;
- condition = condition.replace(/@@/,"'%").replace(/@@/,"%'");
-
- this.defaultCondition = condition;//固定条件;从url里面获取
- caller = this.caller || this.BaseUtil.getUrlParam('whoami');
- if(this.autoQuery) {
- this.getCount(caller, condition);
- } else {
- //易方数据量大 可能明细显示的是datalist
- var gridCondition=this.BaseUtil.getUrlParam('gridCondition');
- if(gridCondition){
- condition=gridCondition.replace(/IS/g, "=");
- this.getCount(caller,condition);
- }
- else this.getCount(caller, '1=2');
- }
- this.callParent(arguments);
- this.addEvents({
- keydown: true
- });
- } ,
- _noc: 0,
- _f: 0,
- getColumnsAndStore: function(c, d, g, s){
- c = c || caller;
- d = d || this.getCondition();
- g = g || page;
- s = s || pageSize;
- var me = this;
- var f = d;
- this.setLoading(true);//loading...
- Ext.Ajax.request({//拿到grid的columns
- url : basePath + 'common/datalist.action',
- params: {
- _noc: (me._noc || getUrlParam('_noc')),
- _f: (me._f || getUrlParam('_f')),
- caller: c,
- condition: f,
- page: g,
- pageSize: s,
- search: me.searchGrid ? 1 : 0// 使用高级查询时,方法有变化
- },
- method : 'post',
- callback : function(options,success,response){
- me.setLoading(false);
- if (!response) return;
- 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);
- if(me.lastSelected && me.lastSelected.length > 0){//grid刷新后,仍然选中上次选中的record
- Ext.each(me.store.data.items, function(item){
- if(item.data[keyField] == me.lastSelected[0].data[keyField]){
- me.selModel.select(item);
- }
- });
- }
- //修改pagingtoolbar信息
- Ext.getCmp('pagingtoolbar').afterOnLoad();
- } else {
- if(!Ext.isChrome){
- Ext.each(res.fields, function(f){
- if(f.type == 'date'){
- f.dateFormat = 'Y-m-d H:m:s';
- }
- });
- }
- var store = Ext.create('Ext.data.Store', {
- fields: res.fields,
- data: data,
- //模糊查询的结果在Ext.Array.filter()方法之后,部分数据被过滤掉,设置为false不调用该方法
- //yingp
- filterOnLoad: false
- });
- //处理render
- var grid = this;
- Ext.Array.each(res.columns, function(column, y) {
- if(!column.haveRendered && column.renderer != null && column.renderer != ""){
- if(!grid.RenderUtil){
- grid.RenderUtil = Ext.create('erp.util.RenderUtil');
- }
- var renderName = column.renderer;
- if(contains(column.renderer, ':', true)){
- var args = new Array();
- Ext.each(column.renderer.split(':'), function(a, index){
- if(index == 0){
- renderName = a;
- } else {
- args.push(a);
- }
- });
- if(!grid.RenderUtil.args[renderName]){
- grid.RenderUtil.args[renderName] = new Object();
- }
- grid.RenderUtil.args[renderName][column.dataIndex] = args;
- //这里只能用column.dataIndex来标志,不能用x,y,index等,
- //grid在render时,checkbox占一列
- }
- column.renderer = grid.RenderUtil[renderName];
- column.haveRendered = true;
- }
- });
- var col = Ext.Array.insert(res.columns, 0, [{xtype: 'rownumberer', width: 35, cls: 'x-grid-header-1', align: 'center'}]);
- me.reconfigure(store, col);//用这个方法每次都会add一个checkbox列
- }
- //修改pagingtoolbar信息
- Ext.getCmp('pagingtoolbar').afterOnLoad();
- //拿到datalist对应的单表的关键词
- keyField = res.keyField;//form表主键字段
- pfField = res.pfField;//grid表主键字段
- url = basePath + res.url;//grid行选择之后iframe嵌入的页面链接
- relative = res.relative;
- if(res.vastbutton && res.vastbutton == 'erpAddButton'){//[新增]功能
- Ext.getCmp('erpAddButton').show();
- }
- }
- });
- },
- 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,
- search: me.searchGrid ? 1 : 0// 使用高级查询时,count的方法有变化
- },
- 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("null"!=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.xtype == 'combo' || f.xtype == 'combofield') {
- if (value == '-所有-') {
- continue;
- } else if (value == '-无-') {
- value = 'nvl(' + fn + ',\' \')=\' \'';
- } else {
- value = fn + " LIKE '" + value + "%' ";
- }
- } else {
- /**字符串转换下简体*/
- var SimplizedValue=this.BaseUtil.Simplized(value);
- //可能就是按繁体筛选
- if(f.ignoreCase) {// 忽略大小写
- fn = 'upper(' + fn + ')';
- value = value.toUpperCase();
- }
- if(!f.autoDim) {
- if(SimplizedValue!=value){
- value = "("+fn + " LIKE '" + value + "%' or "+fn+" LIKE '"+SimplizedValue+"%')";
- }else value = fn + " LIKE '" + value + "%' ";
-
- } else if(f.exactSearch){
- value=fn+"='"+value+"'";
- }else {
- if(SimplizedValue!=value){
- value = "("+fn + " LIKE '%" + value + "%' or "+fn+" LIKE '%"+SimplizedValue+"%')";
- }else value = fn + " LIKE '%" + value + "%' ";
- }
- }
- }
- }
- }
- }else value ="nvl("+fn+",' ')=' '";
- if(condition == null){
- condition = value;
- } else {
- condition = condition + " AND " + value;
- }
- }
- }
- this.filterCondition = condition;
- page = 1;
- this.getCount();
- } else {
- this.allowFilter = true;
- }
- return false;
- }
- },
- reconfigure: function(store, columns){
- //改写reconfigure方法
- var d = this.headerCt;
- if (this.columns.length <= 1 && columns) {//this.columns.length > 1表示grid的columns已存在,没必要remove再add
- d.suspendLayout = true;
- d.removeAll();
- d.add(columns);
- }
- if (store) {
- this.bindStore(store);
- } else {
- this.getView().refresh();
- }
- if (columns) {
- d.suspendLayout = false;
- this.forceComponentLayout();
- }
- this.fireEvent("reconfigure", this);
- },
- getCondition: function(){
- var condition = '';
- if(!Ext.isEmpty(this.defaultCondition)) {
- condition = this.defaultCondition;
- }
- if (this.searchGrid) {
- var s = this.searchGrid.getCondition();
- if(s != null && s.length > 0) {
- if(condition.length > 0)
- condition += ' AND (' + s + ')';
- else
- condition = s;
- }
- }
- if(this.formCondition) {
- if(condition.length > 0)
- condition += ' AND (' + this.formCondition + ')';
- else
- condition = this.formCondition;
- }
- if(!Ext.isEmpty(this.filterCondition)) {
- if(condition == '') {
- condition = this.filterCondition;
- } else {
- condition = '(' + condition + ') AND (' + this.filterCondition + ')';
- }
- }
- return condition;// .replace(/=/g, '%3D')
- }
- });
|