我想在jqgrid上显示一些本地存储在客户端(以JS数组的形式)的数据。但是当我使用jqgrid 3.6.4时,什么也没有发生,而对于jqgrid 4.0.0,它工作得很好。
那么,jqgrid 3.6.4是否支持数据类型:local,或者在这个版本的jqgrid中是否有其他方法来获取本地数据?
我的代码片段如下:objArrayData是数据数组。
jQuery("#testLookupTable").jqGrid({
datatype: 'local',
data: objArrayData,
colNames:['Stmt ID','Code','Definition'],
colModel:[
{name:'id',index:'id', width:0, align:'center', sortable:false, hidden:true},
{name:'code_Q',index:'code_Q', width:20, align:'center', sortable:false},
{name:'defn',index:'defn', width:20, align:'center', sortable:false}
],
autowidth: true,
hoverrows: true,
gridview: true,
height: '100px',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
hidegrid: false
});
更新:
addRowData不能正常工作。它一遍又一遍地重复数组中的数据。在IE中,这会导致stackoverflow。
我的新代码片段: jQuery("testLookupTable").jqGrid({
datatype: 'local',
//data: objArrayCR7,
colNames:['Stmt ID','Code','Definition'],
colModel:[
{name:'id',index:'id', width:0, align:'center', sortable:false, hidden:true},
{name:'code_Q',index:'code_Q', width:20, align:'center', sortable:false},
{name:'defn',index:'defn', width:20, align:'center', sortable:false}
],
autowidth: true,
hoverrows: true,
gridview: true,
height: '100px',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
hidegrid: false,
gridComplete: function(){
$('#testLookupTable').addRowData('code_Q',objArrayCR7);
}
});
(更新):
发现我的错误:
我应该写这行:
$('#testLookupTable').addRowData('code_Q',objArrayCR7);
.jqgrid()之外的。
如果我错了,有人纠正我,我发现每次. addrowdata()运行网格重新加载,所以gridComplete事件每次都被触发。这在前面的代码中创建了一个无限循环。
3.7版本开始支持对data: objArrayData
进行本地jqGrid填充。如果将data
参数与gridview: true
参数一起使用,则接收的最大性能优势。
在3.6.4版本中,您必须根据addRowData填充网格。
我建议您只使用最新版本的jqGrid。当前版本为4.1.2。
发现我的错误了:
我应该写这行:
$('#testLookupTable').addRowData('code_Q',objArrayCR7);
.jqgrid()之外的。
如果我错了,有人纠正我,我发现每次. addrowdata()运行网格重新加载,所以gridComplete事件每次都被触发。这在前面的代码中创建了一个无限循环。