jsonReader Configuration for jqGrid

jsonReader Configuration for jqGrid

本文关键字:jqGrid for Configuration jsonReader      更新时间:2023-09-26

我正在尝试在Jqgrid中渲染数据,但它没有显示出来。我的Json数据来自网络服务器,所以我试图使用Jsonreader作为一个函数来格式化我的数据。谁能指出我的错误吗。提前谢谢。

这是我的jqgrid 代码

jQuery(document).ready(function(){ 
jQuery("#grid").jqGrid({
url: 'localhost/webair/contactinfoes',
datatype: 'json',
ajaxGridOptions: { contentType: "application/json" },
colNames: ['Company','Firstname','Job Title','Last Update Time', 'Last Update User',
'Lastname', 'Uuid'],      
colModel: [
    { name: 'comapany', width: 100},
    { name: 'firstname', width: 60},
    { name: 'jobtitle', width: 100},
    { name: 'lastupdatetime', width: 250, align: 'right' },
    { name: 'lastupdateuser', width: 100, align: 'right' },
    { name: 'lastname', width: 60 },
    { name: 'uuid', width: 250},
],
jsonReader: {
repeatitems: false,
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
},
rowNum:10,
rowList:[10,20,30],
pager: '#pager10',
viewrecords: true,
caption:"Terry's table",
}).navGrid('#gridpager');
})

这是我的json信息;

[ {
"cel":"asdf",
"company":"adsf",
"fax":"asdf",
"firstname":"asdf",
"id":98304,
"jobTitle":"asdf",
"lastUpdateTime":1331831984277,
"lastUpdateUser":"anonymousUser",
"lastname":"berk",
"phone":"adsf",
"uuid":"2asa8a2-d2b5-48a2-ba35-b0cfasdf3170f",
"version":0}]

colModel末尾的小逗号尾部错误可能不是您遇到的主要错误。

实际使用您的代码的演示显示,应该显示网格。如果它没有显示,你应该包括loadError回调函数(见答案)。我想您会遇到"解析错误"异常,这意味着您在服务器响应中得到了错误的"内容类型"HTTP头值。