在使用Easyui DataGrid 過程中,發現若單頁數據量超過300,IE瀏覽器加載速度很慢。也通過網上找尋了很多解決方案,最典型的就是去掉datagrid的自動列寬以及自動行高判斷。
1、解決自動列寬: 設定列寬度可解決。
2、解決自動行高 : 注釋掉下面的代碼。
1 function _3e(_44,_45){ 2 //for(var i=0;i<_45.length;i++){ 3 ////var tr1=$(_44[i]); 4 ////var tr2=$(_45[i]); 5 ////tr1.css("height",""); 6 ////tr2.css("height",""); 7 ////var _46=Math.max(tr1.height(),tr2.height()); 8 ////tr1.css("height",_46); 9 ////tr2.css("height",_46); 10 //} 11 };
使用上述兩種解決辦法后,加載速度有所改觀,但效果不是很明顯。后來使用了datagrid的scrollview和bufferview視圖,scrollview效果仍然不太好,但使用了bufferview后,效果相當明顯,最終選定使用bufferview來加載單頁數據,速度雖然解決了,遇到了另外一個問題,原有的DataGrid做了分頁處理,bufferview在滾動條拉到最底部時候,會自動加載下一頁數據,我已經有了對datagrid的分頁處理,所以這個功能不需要,經多次嘗試,解決方案如下:
1 function scrolling(){ 2 if (getDataHeight() < dc.body2.height() && view.renderedCount < state.data.total){ 3 this.getRows.call(this, target, function(rows){ 4 this.rows = rows; 5 this.populate.call(this, target); 6 dc.body2.triggerHandler('scroll.datagrid'); 7 }); 8 } else if (dc.body2.scrollTop() >= getDataHeight() - dc.body2.height()) { 9 // 注釋掉下面代碼是為了滾動時不加載下一頁數據 10 //this.getRows.call(this, target, function(rows){ 11 // this.rows = rows; 12 // this.populate.call(this, target); 13 //}); 14 } 15 }
將scrolling方法中的else if 里面的代碼塊注釋掉就可以了。