How to load multiple grids faster
我有4个表格。他们使用相同的模态。我不能使用同一存储,因为每个网格都必须发送一个参数值以从db获取数据。因此,发生的事情是我最终创建了4个不同的存储,然后在加载应用程序时,它滞后了,因为它等待加载所有4个存储。这是我的网格..所以我还有3个这样的网格
1 2 3 4 5 6 7 | this.grid1 =Ext.create('Ext.grid.Panel',{ title:'GridView App', store: store, loadMask:true, columns:[ { header:'Q1', sortable:true, dataIndex:'Q1', flex:1,}, { header:'Q2', sortable:true, dataIndex:'Q2', flex:1,}, { header:'Q3', sortable:true, dataIndex:'Q3', flex:1,}, { header:'Q4', sortable:true, dataIndex:'Q4', flex:1,} |
这是我的store1 ...类似地,我还有3个这样的商店,每个商店分别带有参数Q2,Q3,Q4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | var store1 =Ext.create('Ext.data.JsonStore',{ storeId:'myData', scope:this, fields:[ { name:'Q1', type:'int'}, { name:'Q2', type:'int'}, { name:'Q3', type:'int'}, { name:'Q4', type:'int'} ], sorters:[{ property:'Q1', direct:'ASC'}], proxy:{ type:'ajax', url:'GridView/writeRecord', extraParams: { ID: Q1 }, reader: newExt.data.JsonReader({ root:'myTable', totalProperty:'count' }) } }); |
是否有比我现有的方法更快/更好的实现方式?
更新-
第二次更新-
这是我整个应用程序的布局...我的rightcontainer首先被禁用,并包含实际的网格和窗体,然后单击选项卡上的项目启用rightcontainer并加载所有网格。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | Ext.define('ExtjsApp.app1.appPanel', { extend: 'Ext.panel.Panel', alias: 'widget.mypanel', layout: { type: 'vbox', align: 'stretch' }, scope: this, titleAlign: 'center', minWidth: 900, bodyPadding: 10, requires: [], items: [], constructor: function () { this.callParent(arguments); this.regForm = Ext.create('ExtjsApp.app1.RegForm', {}); leftTreeStore = Ext.create('Ext.data.TreeStore', { scope: this, storeId: 'leftTreeStore', fields: [ { name: 'text', type: 'string' }, { name: 'dataId', type: 'string' }, { name: 'listName', type: 'string' }, { name: 'leaf', type: 'bool' } ], root: { expanded: true }, proxy: { type: 'ajax', url: 'app1/getRecords', extraParams: { organization: 'GOOGLE' }, reader: { type: 'json' } }, autoLoad: true, expanded: true, autoSync: true, listeners: { } }); allRecordsStore = Ext.create('Ext.data.TreeStore', { id: 'allRecordsStore', autoLoad: false, autoSync: false, scope: this, fields: [ { name: 'text', type: 'string' }, { name: 'dataId', type: 'string' }, { name: 'listName', type: 'string' }, { name: 'leaf', type: 'bool' } ], root: { expanded: true }, proxy: { type: 'ajax', url: 'app1/getRecords', extraParams: { organization: 'GOOGLE' }, reader: { type: 'json' } } }); this.currentMonthsTree = Ext.create('Ext.tree.TreePanel', { scope: this, title: 'Current 12 Months', titleAlign: 'center', tabIndex: 0, height: 500, flex: 1, rootVisible: false, store: leftTreeStore, id: 'currentMonthsTree', useArrows: true, hideHeaders: true, columns: [ { xtype: 'treecolumn', id: 'ID', dataIndex: 'text', flex: 1 } ], viewConfig: { plugins: { ptype: 'treeviewdragdrop', enableDrop: false, appendOnly: false, enableDrag: false }, listeners: { itemclick: function (view, rec, item) { if (rec.isLeaf()) { alert('isLeaf'); } else if (!rec.isLeaf()) { alert('isNotLeaf'); } } }, allowCopy: true, copy: true } }); this.currentMonthsTree.on('selectionchange', function (selected) { FnDisplayRecord(selected.selected.items[0]); }); this.allRecordsTree = Ext.create('Ext.tree.TreePanel', { scope: this, title: 'All Records', titleAlign: 'center', flex: 1, tabIndex: 1, rootVisible: false, store: allRecordsStore, id: 'allRecordsTree', useArrows: true, hideHeaders: true, columns: [ { xtype: 'treecolumn', id: 'ID', dataIndex: 'text', flex: 1 } ], viewConfig: { plugins: { ptype: 'treeviewdragdrop', enableDrop: false, enableDrag: false, appendOnly: false }, listeners: { itemclick: function (view, rec, item) { if (rec.isLeaf()) { alert('isLeaf'); } else if (!rec.isLeaf()) { alert('isNotLeaf'); } } }, allowCopy: true, copy: true } }); this.allRecordsTree.on('selectionchange', function (selected) { FnDisplayRecord(selected.selected.items[0]); //alert('Hello'); }); function FnClearValues() { //Clear All Values alert('ClearALLValues'); } function FnSetValues(myObj) { //I set all my form values using Ext.getCmp Ext.getCmp('Textl').setValue(myObj.Text1); } function FnDisplayRecord(row) { if (row.get('leaf') == true) { console.log(row.data.dataId); var tempID = row.data.dataId; Ext.getCmp('rightContainer').setLoading(true, true); Ext.getCmp('requisitionPOGridPanel').store.loadData([], false); Ext.Ajax.request({ method: 'GET', url: 'app1/getRecord', headers: { 'Content-Type': 'application/json' }, dataType: 'json', params: { ID: tempID }, success: function (response) { Ext.getCmp('rightContainer').setLoading(false, false); myObj = Ext.JSON.decode(response.responseText); if (AsbestosObj.DateIssued != '') { FnSetValues(AsbestosObj); Ext.getCmp('GridPanel').store.load({ params: { ID: tempID} }); Ext.getCmp('Grid1').store.load({ params: { ID: tempID, qID: 'Q01'} }); Ext.getCmp('Grid2').store.load({ params: { ID: tempID, qID: 'Q02'} }); Ext.getCmp('Grid3').store.load({ params: { ID: tempID, qID: 'Q03'} }); Ext.getCmp('Grid4').store.load({ params: { ID: tempID, qID: 'Q04'} }); } else { FnClearValues(); } }, failure: function () { Ext.Msg.alert('Message', 'Error'); } }); } else if (row.get('leaf') == false) { FnClearValues(); } } this.rightContainer = Ext.create('Ext.form.Panel', { scope: this, id: 'rightContainer', layout: { type: 'vbox', align: 'stretch', pack: 'start' }, autoScroll: true, disabled: true, border: 1, flex: 1, items: [ this.regForm ] }); this.tabContainer = Ext.create('Ext.tab.Panel', { scope: this, activeTab: 0, flex: 0.5, id: 'tabContainer', layout: { type: 'vbox', align: 'stretch' }, plain: true, listeners: { tabchange: function (panel, newTab, oldTab) { Ext.getCmp('rightContainer').disable(); FnClearValues(); var getTabStat = this.getActiveTab(); if (getTabStat.tabIndex == 0) { Ext.getCmp('currentMonthsTree').store.load(); } else if (getTabStat.tabIndex == 1) { Ext.getCmp('allRecordsTree').store.load(); } } }, items: [ this.currentMonthsTree, this.allRecordsTree ] }); this.mainContainer = Ext.create('Ext.container.Container', { scope: this, bodyPadding: 10, title: 'MAIN', layout: { type: 'hbox', align: 'stretch' }, flex: 1, items: [ this.tabContainer, { xtype: 'splitter', width: 5, animate: true }, this.rightContainer ] }); this.add(this.mainContainer); }, loadingOn: function () { setTimeout(function () { Ext.getCmp('currentMonthsTree').setLoading(true, true); }, 100); }, loadingOff: function () { setTimeout(function () { Ext.getCmp('currentMonthsTree').setLoading(false, false); }, 100); } }); |
请参考与我类似的SO问题:组合框加载太慢
基本上,您将需要像通常一样定义所有模型。
然后,您将需要将页面的所有存储定义为没有代理的数组存储,如下所示:
1 2 3 4 5 6 7 8 9 | var myStore1 = Ext.create("Ext.data.ArrayStore", { model:"MyModel1", data: [] }); var myStore2 = Ext.create("Ext.data.ArrayStore", { model:"MyModel1", data: [] }); |
然后,您将想要创建一个调用,无论您从何处获取数据,都需要更改服务器,以将所有数组输出到单个JSON对象中,就像这样,为了进行超级优化,请对其进行处理数组数组,这将是我希望从服务器得到的输出:
1 2 3 4 | { grid_data_1: [...], grid_data_2: [...] } |
然后,在创建所有商店之后,在网页上,进行一次ajax调用以获取所有四个网格的数据:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Ext.Ajax.request({ url: 'url', method: 'GET', params: { ...whatever you want }, success: function (response, opts) { var result = Ext.decode(response.responseText); myStore1.loadData(result.grid_data_1); myStore2.loadData(result.grid_data_2); ... }, }); |
这将使其效率更高,您可能不需要使用数组数组,因为每个网格只有5行,但是将4个Ajax调用优化为一个应该产生很大的影响。
您在这里不能做更多的事情。我认为您可以进行一些微调,但我怀疑它们是否值得花时间进行识别。如果您的应用执行以下操作,则说明一切正确;
- 直到您加载的时间
- 仅初始化所需的控制器和存储(检查每个请求)
- 显示主视图
一旦渲染了网格,它们将至少在具有分页工具栏的情况下触发加载操作。您可以更早地开始加载操作,这意味着在创建可能会花费几毫秒的视图之前,但是我怀疑您可以节省更多时间。
这当然是基于可用信息的。