从数据数组中填充jqGrid
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从数据数组中填充jqGrid相关的知识,希望对你有一定的参考价值。
我有这样的jqGrid
jQuery("#list2").jqGrid({
datatype: "local",
colNames: ['Name', 'Email', 'Mobile', 'Address', 'Institution', 'Studying Year', 'Registered Date', 'No Of Courses', 'Book Codes'],
colModel: [
{name: 'name',index: 'name',align: "center"},
{name: 'user_email',index: 'user_email',align: "center"},
{name: 'mobile',index: 'mobile',align: "center"},
{name: 'address',index: 'address',align: "center"},
{name: 'institution',index: 'institution',align: "center"},
{name: 'studyingyear',index: 'studyingyear',align: "center"},
{name: 'created',index: 'created',align: "center"},
{name: 'noofcourses',index: 'noofcourses',align: "center"},
{name: 'book_code',index: 'book_code',align: "center"}
],
gridview: true
});
$.ajax({
url:'http://localhost:8090/cbsapp/adminlogin/serverforusers.php?limit=20&offset=0',
dataType: 'json'
}).done(function(data) {
var jqData = data.rows
console.log(jqData);
for(var i=0;i<=jqData.length;i++)
jQuery("#list2").jqGrid('addRowData',i+1,jqData[i]);
}).fail(function(error){
console.log(error)
})
我收到的数据是数组
[{
"id": "1",
"cell": [" Kousic Prabu Mohanasundaravad", "magickousi@gmail.com", "9159360960", "263A,Thattankulam rd, Puthunagar, Palani", "YSMU", "Others", "2017-12-08 09:33:31", "1", ["FMGE DS"]]
}, {
"id": "2",
"cell": [" Navdeep", "navdeepgohel@gmail.com", "9207367900", "Kevadiya colony ", "DIAMS ", "Final year", "2017-11-20 23:08:13", "0", [null]]
}, {
"id": "3",
"cell": [" Nikish nehra", "nikishnehra01@gmail.com", "8168965998", "Hissar cantt hissar ", "Kharkiv national medical university ", "Final year", "2017-12-11 04:35:34", "1", ["FMGE DS"]]
}, {
"id": "4",
"cell": [" Vynatheya Chowdary", "vyna984@gmail.com", "7032207755", "d.no:3270 putlur road tadipatri Anantapur ", "Government Medical College, Anantapur", "3 Year", "2017-08-29 01:47:16", "1", ["SOCH UB"]]
}]
我使用单元格键作为数组来填充数据:
for(var i=0;i<=jqData.length;i++)
jQuery("#list2").jqGrid('addRowData',i+1,jqData[i]);
但是数据没有显示在网格中,但表格/网格是使用所有空行正确创建的。请帮忙。
答案
你应该添加
localReader: { repeatitems: true }
jqGrid的选项,因为您使用的是JSON格式。另外,在循环中使用addRowData
填充网格中的数据非常糟糕。使用jqGrid的data
参数更有效。以https://jsfiddle.net/s5m43jme/为例。一个
以上是关于从数据数组中填充jqGrid的主要内容,如果未能解决你的问题,请参考以下文章
ASP.net MVC 代码片段问题中的 Jqgrid 实现
jqGrid:使用 beforeProcessing 填充 filterToolbar 选择框