jqgrid json reader for arcgis server query results

后端 未结 1 1899
星月不相逢
星月不相逢 2020-12-02 02:37

what kind of json reader I need to plot data like these in a jqgrid?

Thanks!

相关标签:
1条回答
  • 2020-12-02 03:23

    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:

    enter image description here

    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.

    0 讨论(0)
提交回复
热议问题