太复杂了,得封装个简单的
Ext.namespace("Ext.ux.yiminghe") Ext.ux.yiminghe.JsonGridPanel = function (config) { var fieldsData = []; for (var i = 0; i < config.columns.length; i++) { fieldsData.push(config.columns[i].dataIndex); } //config.baseParams=config.baseParams||[]; //config.baseParams.limit=config.pageSize; //config.baseParams.start=0; config.store = new Ext.data.JsonStore({ url: config.dataSource, //读取数据的url, root: 'rows', baseParams:config.baseParams, totalProperty:'results', //总共的页数 fields: fieldsData }); config.store.lastOptions={params:{start:0,limit:config.pageSize}}; var columns = [new Ext.grid.RowNumberer()]; for (var i = 0; i < config.columns.length; i++) { if (config.columns[i].show) columns.push(config.columns[i]); } config.columns = columns; Ext.ux.yiminghe.JsonGridPanel.addMenuScope(config.tbar, this); config.store.on('loadexception', function(othis, options, response, e) { if(response.responseText.trim() !='') Ext.Msg.alert('注意', response.responseText); else Ext.Msg.alert('注意','网络出问题了'); return; }); if (config.dynamicFunc) config.store.on('beforeload', function(store_, options) { config.dynamicFunc(options.params); }); if (config.maskAll) config.loadMask = new Ext.LoadMask(Ext.getBody(), {msg:"加载中..."}); else config.loadMask = true; config.bbar = new Ext.PagingToolbar({ //在grid底层添加分页工具栏 pageSize:config.pageSize, //显示的数据条数 store: config.store, //选择翻页按钮时的加载到grid的数据 displayInfo:true , items:config.pageBarItems, plugins:config.pageBarPlugins })//end bbar; Ext.apply(this, config); Ext.ux.yiminghe.JsonGridPanel.superclass.constructor.call(this,arguments); if (this.doubleClick) { this.on('rowdblclick', function(grid2, rowIndex, ee) { var store = grid2.getStore(); var oRecord = store.getAt(rowIndex); this.doubleClick(oRecord); ee.stopEvent(); }, this); } if (this.singleClick) { this.on('rowclick', function(grid2, rowIndex, ee) { var store = grid2.getStore(); var oRecord = store.getAt(rowIndex); this.singleClick(oRecord); ee.stopEvent(); }, this); } if (this.rowcontextmenu) { Ext.ux.yiminghe.JsonGridPanel.addMenuScope(this.rowcontextmenu, this); this.on('rowcontextmenu', function(grid2, rowIndex, ee) { if (!this.rowcontextmenu_) { this.rowcontextmenu_ = Ext.menu.MenuMgr.get({ id:'rowcontextmenu_-ctx', items: this.rowcontextmenu }); } this.getSelectionModel().selectRow(rowIndex); this.rowcontextmenu_.showAt(ee.getXY()); ee.preventDefault(); }, this); } } Ext.extend(Ext.ux.yiminghe.JsonGridPanel, Ext.grid.GridPanel, { getSelectionRecords:function() { if (this.getSelectionModel().getSelections()[0]) return this.getSelectionModel().getSelections(); else { alert('请选择数据!'); return false; } }, reload:function() { this.getStore().reload(); } , getSelectionRecord:function() { if (this.getSelectionModel().getSelections()[0]) return this.getSelectionModel().getSelections()[0]; else { alert('请选择数据!'); return false; } } }); Ext.ux.yiminghe.JsonGridPanel.addMenuScope = function (obj, sco) { if (!obj) return; if(obj.length) for (var i = 0; i < obj.length; i++) { if (!obj[i] || typeof obj[i] == 'string') continue; obj[i]['scope'] = sco; if (obj[i].menu) yiminghe.dynamicTable.addMenuScope(obj[i].menu, sco); } }