DataSource used with ESRI ARCGIS REST services?

3 posts, 0 answers
  1. Kevin F
    Kevin F avatar
    46 posts
    Member since:
    Sep 2009

    Posted 05 Jun 2014 Link to this post

    I've searched everywhere and have finally come here to ask for help :)

    Has anyone had any success using ESRI's REST services with a Kendo DataSource?

    The problem is that the REST service is not just returning the results.  It has a bunch of "meta" data in the JSON before the result set, and it actually encloses the results in an array of objects.  Each object has a "geometry" field and an "attributes" field.  The actual results are in the attributes field.

    So...  here is what I have for the transport.read:
    transport: {
        read: function(options) {
            $.ajax({
                url: crudBaseUrl + "/query",
                dataType: "json",
                data: {
                    f: "json",
                    token: token,
                    outFields: "*",
                    returnGeometry: true,
                    outSR: 3857,
                    where: "LN_NO='" + ownerid + "'"
                },
                type: "POST",
                success: function(result) {
                    window.successResult = result;
                    options.success(result.features);
                }
            });
        },

    Here is the model:
    model: {
            id: "OBJECTID",
            fields: {
                    OBJECTID: { type: "number", editable: false },
                    LN_NO: { type: "string" },
                    QSEC: { type: "string" },
                    SECTION: { type: "string" },
                    TOWNSHIP: { type: "string" },
                    N_S: { type: "string" },
                    RANGE: { type: "string" },
                    E_W: { type: "string" },
                    AF: { type: "string" },
                    LATITUDE: { type: "string" },
                    LONGITUDE: { type: "string" },
                    METHODCODE: { type: "string" },
                    REFERENCE: { type: "string" },
                    ACCURACY: { type: "string" },
                    R: { type: "string" }
            }
    }

    And here is the column set I use in the Grid to display.  Note I have to use "attributes.<field_name>" in order for it to display properly.
    columns: [
                        {
                            field: "attributes.OBJECTID",
                            title: "OID",
                        },
                        {
                            field: "attributes.LN_NO",
                            title: "Loc Number",
                        },
                        {
                            field: "attributes.QSEC",
                            title: "QSEC"
                        },
                        {
                            field: "attributes.SECTION",
                            title: "Section",
                        },
                        {
                            field: "attributes.TOWNSHIP",
                            title: "Township"
                        },
                        {
                            field: "attributes.N_S",
                            title: "N / S"
                        },
                        {
                            field: "attributes.RANGE",
                            title: "Range"
                        },
                        {
                            field: "attributes.E_W",
                            title: "E / W"
                        },
                        {
                            field: "attributes.AF",
                            title: "Acre/Feet"
                        },
                        {
                            field: "attributes.LATITUDE",
                            title: "Latitude"
                        },
                        {
                            field: "attributes.LONGITUDE",
                            title: "Longitude"
                        },
                        {
                            field: "attributes.METHODCODE",
                            title: "Method Code"
                        },
                        {
                            field: "attributes.REFERENCE",
                            title: "Reference"
                        },
                        {
                            field: "attributes.ACCURACY",
                            title: "Accuracy"
                        },
                        {
                            field: "attributes.R",
                            title: "Reservation"
                        },
                        { command: ["edit", "destroy"], title: " ", width: "200px" }
                    ],

    The initial issue was that the row in the grid was disappearing if I hit EDIT then CANCEL.  I found out why that is happening - it's because all of the field values I have defined in the datasource are undefined.

    Any help is greatly appreciated!

    K

  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 10 Jun 2014 Link to this post

    Hi Kevin,

    I would suggest to update the grid and it's dataSource settings as demonstrated below:

    1) Update dataSource transport CRUD operations to remove the nested ajax methods (you can pass the same options directly to the "read" operation):
    transport: {
        read: {
            url: crudBaseUrl + "/query",
            dataType: "json",
            data: {
                f: "json",
                token: token,
                outFields: "*",
                returnGeometry: true,
                outSR: 3857,
                where: "LN_NO='" + ownerid + "'"
            },
            type: "POST"
        },

    2) Add dataSource "schema.parse" function which to parse the data correctly (remove the parent "attributes" object). Optionally you can use the dataSource "transport.parameterMap" function to format the response to the server.

    e.g.:
    schema: {
        parse: function (data) {
            data = data.features;
            for (var i = 0; i < data.length; i++) {
                data[i].OBJECTID = data[i].attributes.OBJECTID;
                data[i].QSEC = data[i].attributes.QSEC;
                data[i].SECTION = data[i].attributes.SECTION;
                data[i].TOWNSHIP = data[i].attributes.TOWNSHIP;
                data[i].RANGE = data[i].attributes.RANGE;
                //list other fields as well
            }
            return data;
        },
        model: {

    3) Update the grid columns to remove the "attributes" field:
    columns: [
        {
            field: "OBJECTID",
            title: "OID",
        },
        {
            field: "LN_NO",
            title: "Loc Number",
        },
        {
            field: "QSEC",
            title: "QSEC"
        },
        {
            field: "SECTION",
            title: "Section",
        },
        {
            field: "TOWNSHIP",
            title: "Township"
        },
        {
            field: "N_S",
            title: "N / S"
        },
        {
            field: "RANGE",
            title: "Range"
        },
        {
            field: "E_W",
            title: "E / W"
        },
        {
            field: "AF",
            title: "Acre/Feet"
        },
        {
            field: "LATITUDE",
            title: "Latitude"
        },
        {
            field: "LONGITUDE",
            title: "Longitude"
        },
        {
            field: "METHODCODE",
            title: "Method Code"
        },
        {
            field: "REFERENCE",
            title: "Reference"
        },
        {
            field: "ACCURACY",
            title: "Accuracy"
        },
        {
            field: "R",
            title: "Reservation"
        },

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Kevin F
    Kevin F avatar
    46 posts
    Member since:
    Sep 2009

    Posted 29 Aug 2014 in reply to Vladimir Iliev Link to this post

    Thank you!

    I will give this a try as soon as I get the chance.

    Kevin
Back to Top