jqgrid json reader for arcgis server query results

穿精又带淫゛_ 提交于 2019-11-27 09:52:20

You have strange questions and all about the jsonReader. In the current case you can use

jsonReader: {
    root: 'features',
    repeatitems: false
}

to read the data. The demo shows how the results can looks like:

UPDATED: How I understand, what you want really to do is to call some external URL which provide you back the JSON. Standard Ajax request can't be done to another server because of security reasons (see same origin policy). Fortunately the server sampleserver1.arcgisonline.com/ArcGIS supports JSONP requests. So to fill the grid with external data you can use the following code

$('#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'
});

See the new demo here.

UPDATED 2: To be able to use local searching/filtering one should modify the above code. It's better to replace postData which one sees above to the following parameters

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 the corresponding demo where filterToolbar works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!