當我進行批量編輯(一次內聯編輯100行)時,需要最新版本的free-jqgrid的幫助。在JQGrid 4.3.1中非常快速在升級到free-jqgrid 4.13.6之後,我發現它非常慢。我撰寫了一個類似的例子。這個獨立的例子在性能上並不差。但我不確定爲什麼在我的應用程序中進行內聯編輯需要很長時間。任何提示將是一個很大的幫助。 在此示例中,選中多選複選框(位於網格的左上角),然後單擊按鈕(位於頂部)。基本上試圖瞭解何時進行內聯編輯所有因素都考慮在內。free-jqgrid中的大量編輯性能
注意:剛纔意識到單行內聯編輯也需要2-3秒。這在4.3.1中非常快。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>http://stackoverflow.com/q/27617764/315935</title>
<meta name="author" content="Oleg Kiriljuk">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!--<link rel="stylesheet" href="jqGrid/css/ui.jqgrid.css">-->
<link rel="stylesheet" href="http://rawgit.com/free-jqgrid/jqGrid/master/css/ui.jqgrid.css">
<style type="text/css">
html, body { font-size: 75%; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$.jgrid = $.jgrid || {};
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script src="http://rawgit.com/free-jqgrid/jqGrid/master/js/jquery.jqgrid.src.js"></script>
<!--<script src="jqGrid/js/jquery.jqGrid.src.js"></script>-->
<script type="text/javascript">
//<![CDATA[
/*global $ */
/*jslint eqeq: true, browser: true, plusplus: true */
$(function() {
"use strict";
var $grid = $("#list"),
gridData,
startTime,
measureTime = false,
timeInterval;
var date = new Date(), t = Object.prototype.toString.call(date), t1 = String(date);
//alert("start to generate the data");
// gridData = getGridData(100);
// console.log(gridData);
//alert("start to fill the grid")
startTime = new Date();
$grid.jqGrid({
datatype: 'json',
url: 'https://api.myjson.com/bins/efhbt',
mtype: 'GET',
colNames: ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm'],
colModel: [
{ name: "aa", label: "c01" },
{ name: "bb", label: "c02" },
{ name: "cc", label: "c03" },
{ name: "dd", label: "c04" },
{ name: "ee", label: "c05" },
{ name: "ff", label: "c06" },
{ name: "gg", label: "c07", editable: true, stype: 'select', formatter: 'select',
edittype: 'select', editoptions: {
value: 'Select:Select;Y:Yes;N:No',
multiple: false
}
},
{ name: "hh", label: "c08", editable: true, stype: 'select', formatter: 'select',
edittype: 'select', editoptions: {
value: 'Select:Select;Y:Yes;N:No',
multiple: false
}
},
{ name: "ii", label: "c09", editable: true, stype: 'select', formatter: 'select',
edittype: 'select', editoptions: {
value: 'Select:Select;Y:Yes;N:No',
multiple: false
}
},
{ name: "jj", label: "c10", editable: true },
{ name: "kk", label: "c11", editable: true },
{ name: "ll", label: "c12", editable: true },
{ name: "mm", label: "c13", editable: true }
],
cmTemplate: { width: 100, autoResizable: true },
rowNum: 1000,
records: 1000,
rownumWidth: 40,
rowList: [20, 100, 1000, 10000, "100000:All"],
viewrecords: true,
rownumbers: true,
toppager: false,
pager: false,
shrinkToFit: false,
multiselect: true,
editurl: 'clientArray',
loadonce: true,
onSortCol: function() {
startTime = new Date();
measureTime = true;
},
/*onSelectRow: function (rowid) {
var $self = $(this),
savedRow = $self.jqGrid("getGridParam", "savedRow");
if (savedRow.length > 0) {
$self.jqGrid("restoreRow", savedRow[0].id);
}
$self.jqGrid("editRow", rowid);
},*/
loadComplete: function() {
if (measureTime) {
setTimeout(function() {
alert("Total loading time: " + timeInterval + "ms");
}, 50);
measureTime = false;
}
},
autoencode: true,
caption: "Shows the performance of resizing. Make double-click on the column resizer"
}).jqGrid("filterToolbar", {
beforeSearch: function() {
startTime = new Date();
measureTime = true;
return false; // allow filtering
}
}).jqGrid("gridResize");
timeInterval = new Date() - startTime;
setTimeout(function() {
// alert("Total time: " + timeInterval + "ms");
}, 50);
// On Click Of Button
$("#Change_Value").click(function() {
var v = $("#name").val();
var myGrid = $("#list");
var selRowIds = myGrid.jqGrid("getGridParam", "selarrrow");
//alert(selRowId.length);
for (var i = 0; i < selRowIds.length; i++) {
//rowData = myGrid.jqGrid("getLocalRow", selRowIds[i]);
// one can uses the data here
myGrid.jqGrid("editRow", selRowIds[i], true);
}
});
});
//]]>
</script>
</head>
<body>
<div>
<input type="text" name="name" id="name" />
<input type="button" name="Change_Value" id="Change_Value" value="Change Value" />
</div>
<div>
<table id="list"></table>
</div>
</body>
</html>
我完全理解,顯示100行是一個非常糟糕的想法。在我的情況下,搜索結果中有大約5000行。根據客戶的要求,我們必須顯示100行。現在我擔心的是,升級到4.13後,性能太慢了。所以試圖瞭解我可以做些什麼來使其每行100行更快。我會嘗試與顯示/隱藏並保持張貼。謝謝。 – SKumar
是的,我看到有更好的表現。我想知道(實際上試圖在技術上理解)如何通過隱藏和顯示來實現。爲此非常感謝。不過,我仍然看到我們的生產/分段環境中的文件數量與DEV相同。注意:所有硬件配置相同。而且我也看到冰凍柱高度有問題。編輯完所有的粗體後,DIV(凍結列)的高度比te網格大約多20px。我將在演示示例中嘗試並更新。 – SKumar
@SKumar:不客氣!您是否閱讀了關於**網頁瀏覽器重排**的[文章](https://developers.google.com/speed/articles/reflow)?它描述了頁面發生多重變化時性能下降的原因。隱藏元素的變化減少了迴流工作的一部分。如果您在網格中使用凍結列,那麼您應該在循環之前調用'destroyFrozenColumns'銷燬凍結列,在那裏調用'editRow',然後通過新調用'setFrozenColumns'重新創建凍結列。它應該額外提高性能。 – Oleg