我有一个用JQuery编写的应用程序,我使用JqGrid和Ajax JSON调用来调用数据库中的存储过程,使用VB作为我的代码隐藏语言。
这一切都很好,直到我得到2k结果+。
当我得到超过2-3k的结果时,程序崩溃了。
我读到grd_Order.jqGrid('addRowData', i + 1, data.d[i]);
的地方
是一种向网格添加数据的低效方法。我还有其他什么可能性?
我的代码看起来有点像这样:
grd_Order.jqGrid({
datatype: "local",
data: order_Data,
colNames: ['OrdNo', 'IdCust', 'CustName', 'CustAdd', 'CustZip', 'CustPhone', 'InvNo', 'InvDate', 'VehRef', 'VehReg', 'Prefix', 'WOSeries', 'PayType', 'OrderType', 'Status', 'OrderStatus'],
colModel: [{ name: 'ORDNO', index: 'ORDNO', sorttype: "string", classes: 'wosearchpointer', width: 75 },
{ name: 'IDCUSTOMER', index: 'IDCUSTOMER', sorttype: "string", classes: 'wosearchpointer', width: 65 },
{ name: 'CUSTOMER', index: 'CUSTOMER', sorttype: "string", classes: 'wosearchpointer', width: 150 },
{ name: 'CUSTADD1', index: 'CUSTADD1', sorttype: "string", classes: 'wosearchpointer', width: 100 },
{ name: 'CUSTZIP', index: 'CUSTZIP', sorttype: "string", classes: 'wosearchpointer', width: 50 },
{ name: 'CUSTPHONEMOBILE', index: 'CUSTPHONEMOBILE', sorttype: "string", classes: 'wosearchpointer', width: 75 },
{ name: 'InvNo', index: 'InvNo', sorttype: "string", classes: 'wosearchpointer', width: 75 },
{ name: 'InvDate', index: 'InvDate', sorttype: "string", classes: 'wosearchpointer', width: 80 },
{ name: 'REFNO', index: 'REFNO', sorttype: "string", classes: 'wosearchpointer', width: 80 },
{ name: 'REGNO', index: 'REGNO', sorttype: "string", classes: 'wosearchpointer', width: 80 },
{ name: 'PREFIX', index: 'PREFIX', sorttype: "string",hidden:true },
{ name: 'WOSeries', index: 'WOSeries', sorttype: "string", hidden: true },
{ name: 'PayType', index: 'PayType', sorttype: "string", hidden: true },
{ name: 'OrderType', index: 'OrderType', sorttype: "string", classes: 'wosearchpointer', width: 60 },
{ name: 'STATUS', index: 'STATUS', sorttype: "string", classes: 'wosearchpointer', width: 60 },
{ name: 'OrderStatus', index: 'OrderStatus', sorttype: "string", classes: 'wosearchpointer', width: 60 }
],
pager: jQuery('#pagerOrd'),
hidegrid: false,
rowNum: pageSize,//can fetch from webconfig
rowList: 5,
viewrecords: true,
height: 350,
async: false, //Very important,
subGrid: false,
autoWidth: true,
shrinkToFit: true,
sortorder: "desc",
sortname: 'ORDNO'
});
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "frmWOSearchPopup.aspx/Order_Search",
data: "{q: '" + s + "', 'isBargain': '" + isBargain + "', 'isOrder': '" + isOrder +"', 'isCreditnote': '" + isCreditnote + "'}",
dataType: "json",
async: false,//Very important
success: function (data) {
for (i = 0; i < data.d.length; i++)
{
grd_Order.jqGrid('addRowData', i + 1, data.d[i]);
}
jQuery("#grdOrder").setGridParam({ rowNum: pageSize }).trigger("reloadGrid");
}
});
}
正如您所看到的,这个for循环可以循环数千次。这是一种很好的做事方式吗?我怎样才能更好/更有效率?