123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- /**
- * ERP项目gridpanel通用样式2
- */
- Ext.define('erp.view.core.grid.Panel2',{
- extend: 'Ext.grid.Panel',
- alias: 'widget.erpGridPanel2',
- requires: ['erp.view.core.toolbar.Toolbar', 'erp.view.core.plugin.CopyPasteMenu'],
- region: 'south',
- layout : 'fit',
- id: 'grid',
- emptyText : $I18N.common.grid.emptyText,
- columnLines : true,
- autoScroll : true,
- store: [],
- columns: [],
- binds:null,
- bodyStyle: 'background-color:#f1f1f1;',
- plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit: 1,
- listeners:{
- beforeedit:function(e){
- var g=e.grid,r=e.record,f=e.field;
- if(g.binds){
- var bool=true;
- Ext.Array.each(g.binds,function(item){
- if(Ext.Array.contains(item.fields,f)){
- Ext.each(item.refFields,function(field){
- if(r.get(field)!=null && r.get(field)!=0 && r.get(field)!='' && r.get(field)!='0'){
- bool=false;
- }
- });
- }
- });
- return bool;
- }
- }
- }
- }), Ext.create('erp.view.core.plugin.CopyPasteMenu')],
- features : [Ext.create('Ext.grid.feature.GroupingSummary',{
- startCollapsed: true,
- groupHeaderTpl: '{name} (共:{rows.length}条)'
- }),{
- ftype : 'summary',
- showSummaryRow : false,//不显示默认合计行
- generateSummaryData: function(){
- // 避开在grid reconfigure后的计算,节约加载时间50~600ms
- return {};
- }
- }],
- bbar: {xtype: 'erpToolbar',id:'toolbar'},
- GridUtil: Ext.create('erp.util.GridUtil'),
- BaseUtil: Ext.create('erp.util.BaseUtil'),
- necessaryField: '',//必填字段
- detno: '',//编号字段
- keyField: '',//主键字段
- mainField: '',//对应主表主键的字段
- dbfinds: [],
- caller: null,
- condition: null,
- gridCondition:null,
- initComponent : function(){
- if(!this.boxready) {
- if(this._buttons)
- this.bbar._buttons = this._buttons;// 在toolbar加入grid固定按钮
- var condition = this.condition;
- 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;
- }
- var gridParam = {caller: this.caller || caller, condition: this.gridCondition||condition, _m: 0};
- var master = getUrlParam('newMaster'),_config=getUrlParam('_config');
- if(master){
- gridParam.master = master;
- }
- if(_config)gridParam._config=_config;
- var _copyConf=getUrlParam('_copyConf');
- if(_copyConf!=null){//复制来源单据的条件
- gridParam._copyConf=_copyConf;
- }
- this.GridUtil.getGridColumnsAndStore(this, 'common/singleGridPanel.action', gridParam, "");//从后台拿到gridpanel的配置及数据
- }
- this.callParent(arguments);
- if(!this.boxready) {
- if(this.allowExtraButtons)// 加载其它按钮
- this.on('reconfigure', this.loadExtraButton, this, {single: true, delay: 1000});
- this.on('summary', this.generateSummaryData, this, {single: true, delay: 1000});
- }
- },
- getEffectiveData: function(){
- var me = this;
- var effective = new Array();
- var s = this.store.data.items;
- for(var i=0;i<s.length;i++){
- var data = s[i].data;
- if(data[me.keyField] != null && data[me.keyField] != ""){
- effective.push(data);
- }
- }
- return effective;
- },
- setReadOnly: function(bool){
- this.readOnly = bool;
- },
- reconfigure: function(store, columns){
- var me = this,
- view = me.getView(),
- originalDeferinitialRefresh,
- oldStore = me.store,
- headerCt = me.headerCt,
- oldColumns = headerCt ? headerCt.items.getRange() : me.columns;
- if (columns) {
- columns = Ext.Array.slice(columns);
- }
- me.fireEvent('beforereconfigure', me, store, columns, oldStore, oldColumns);
- if (me.lockable) {
- me.reconfigureLockable(store, columns);
- } else {
- Ext.suspendLayouts();
- if (columns) {
- delete me.scrollLeftPos;
- headerCt.removeAll();
- headerCt.add(columns);
- }
- if (store && (store = Ext.StoreManager.lookup(store)) !== oldStore) {
- originalDeferinitialRefresh = view.deferInitialRefresh;
- view.deferInitialRefresh = false;
- try {
- me.bindStore(store);
- } catch ( e ) {
- }
- view.deferInitialRefresh = originalDeferinitialRefresh;
- } else {
- me.getView().refresh();
- }
- Ext.resumeLayouts(true);
- }
- me.fireEvent('reconfigure', me, store, columns, oldStore, oldColumns);
- this.fireEvent("summary", this);
- },
- generateSummaryData : function() {
- var store = this.store,
- columns = this.columns, s = this.features[this.features.length - 1],
- i = 0, length = columns.length, comp, bar = this.down('erpToolbar');
- if (!bar) return;
- //将feature的data打印在toolbar上面
- for (; i < length; i++ ) {
- comp = columns[i];
- if(comp.summaryType) {
- var tb = Ext.getCmp(comp.dataIndex + '_' + comp.summaryType);
- if(!tb){
- bar.add('-');
- tb = bar.add({
- id: comp.dataIndex + '_' + comp.summaryType,
- itemId: comp.dataIndex,
- xtype: 'tbtext'
- });
- }
- var val = s.getSummary(store, comp.summaryType, comp.dataIndex, false);
- if(comp.xtype == 'numbercolumn') {
- val = Ext.util.Format.number(val, (comp.format || '0,000.000'));
- }
- tb.setText(comp.text + ':' + val);
- }
- }
- },
- /**
- * Grid上一条
- */
- prev: function(grid, record){
- grid = grid || Ext.getCmp('grid');
- record = record || grid.selModel.lastSelected;
- if(record){
- //递归查找上一条,并取到数据
- var d = grid.store.getAt(record.index - 1);
- if(d){
- try {
- grid.selModel.select(d);
- return d;
- } catch (e){
- }
- } else {
- if(record.index - 1 > 0){
- return this.prev(grid, d);
- } else {
- return null;
- }
- }
- }
- },
- /**
- * Grid下一条
- */
- next: function(grid, record){
- grid = grid || Ext.getCmp('grid');
- record = record || grid.selModel.lastSelected;
- if(record){
- //递归查找下一条,并取到数据
- var d = grid.store.getAt(record.index + 1);
- if(d){
- try {
- grid.selModel.select(d);
- return d;
- } catch (e){
- }
- } else {
- if(record.index + 1 < grid.store.data.items.length){
- return this.next(grid, d);
- } else {
- return null;
- }
- }
- }
- },
- allowExtraButtons: false,// 加载其它按钮,从GridButton加载
- loadExtraButton: function() {
- var me = this;
- Ext.Ajax.request({
- url : basePath + "common/gridButton.action",
- params: {
- caller: caller
- },
- method : 'post',
- async: false,
- callback : function(options, success, response){
- var r = new Ext.decode(response.responseText);
- if(r.exceptionInfo){
- showError(r.exceptionInfo);
- }
- if(r.buttons){
- var buttons = Ext.decode(r.buttons), tb = me.down('#toolbar');
- if(tb) {
- Ext.each(buttons, function(b){
- try {
- tb.add({
- xtype: b.xtype,
- disabled: true,
- style: {
- marginLeft: '0'
- }
- });
- } catch(e) {
- tb.add({
- text: $I18N.common.button[b.xtype],
- id: b.xtype,
- cls: 'x-btn-gray',
- disabled: true
- });
- }
- });
- }
- }
- }
- });
- }
- });
|