你有一些奇怪的问题以及关于jsonReader
。在当前情况下,您可以使用
jsonReader: {
root: 'features',
repeatitems: false
}
读取数据。The demo http://www.ok-soft-gmbh.com/jqGrid/user781065_.htm显示结果如下:
UPDATED: 我的理解是,你真正想做的就是打电话给一些人external为您提供返回 JSON 的 URL。由于安全原因,标准 Ajax 请求无法发送到另一台服务器(请参阅同源政策 http://en.wikipedia.org/wiki/Same_origin_policy)。幸好服务器sampleserver1.arcgisonline.com/ArcGIS
支持 JSONP 请求。因此,要使用外部数据填充网格,您可以使用以下代码
$('#grid').jqGrid({
url: 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/4/query',
datatype: 'jsonp',
postData: $.param({
where: "1=1",
returnGeometry: false,
outFields: "ObjectID,NAME,STATE_NAME,CNTY_FIPS",
f: "json"
}),
colModel: [
{name: 'ObjectID', label: 'ID', width: 60, jsonmap: 'attributes.ObjectID'},
{name: 'NAME', label: 'Name', width: 150, jsonmap: 'attributes.NAME'},
{name: 'STATE_NAME', label: 'State', width: 120, jsonmap: 'attributes.STATE_NAME'},
{name: 'CNTY_FIPS', label: 'FIPS', width: 60, jsonmap: 'attributes.CNTY_FIPS'}
],
toppager: true,
jsonReader: {
root: 'features',
repeatitems: false
},
loadonce: true,
ignoreCase: true,
height: 'auto'
});
查看新演示here http://www.ok-soft-gmbh.com/jqGrid/user781065_jsonp.htm.
更新2:为了能够使用本地搜索/过滤,应该修改上面的代码。最好更换postData
上面哪个看到下面的参数
ajaxGridOptions: { cache: true },
prmNames: {search: null, nd: null, sort: null, rows: null, order: null, page: null},
postData: {
where: "1=1",
returnGeometry: false,
outFields: "ObjectID,NAME,STATE_NAME,CNTY_FIPS",
f: "json"
}
See 对应的演示 http://www.ok-soft-gmbh.com/jqGrid/user781065_jsonp_.htm where filterToolbar
works.