从数据数组中填充jqGrid

时间:2017-12-22 03:55:55

标签: jquery 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]);

但是数据不在网格中,但表格/网格是用所有空白行正确创建的。 请帮忙。

1 个答案:

答案 0 :(得分:0)

你应该添加

localReader: { repeatitems: true }
jqGrid的

选项,因为您使用的是JSON格式。另外,在循环中使用addRowData来填充网格中的数据非常糟糕。使用jqGrid的data参数代替它会更有效。请参阅https://jsfiddle.net/s5m43jme/作为示例。甲