WCF Datasource for MVVM Grid with server paging

3 posts, 1 answers
  1. Lance
    Lance avatar
    25 posts
    Member since:
    Apr 2013

    Posted 29 Jan 2015 Link to this post

    Hi,
    I have an MVVM Grid that is getting data from a WCF service.  It all works apart from the format of the data that arrives at the datasource.  The json is

    {"GetRequestSummaryRestResult":"{\"Data\":[{\"Id\":0.0,\"RequestId\":121.0,\"Creator\":\"Elmer Fudd\",\"Recipient\":\"Bugs Bunny\",\"Assignee\":null,\"RequestType\":\"EquipmentLoan\",\"Description\":\"Mobile phone with the Android operating system\",\"CreationDate\":\"2015-01-14T10:45:09\",\"Status\":null,\"Comments\":null},{\"Id\":1.0,\"RequestId\":2.0,\"Creator\":\"Porky Pig\",\"Recipient\":\"Tweety Pie\",\"Assignee\":null,\"RequestType\":\"EquipmentAcquisition\",\"Description\":\"Holds the laptop at eye height\",\"CreationDate\":\"2014-06-03T11:27:38\",\"Status\":null,\"Comments\":\"me has\"}],\"Total\":11}"}.  For some reason the Data and Total are wrapped in an object that is the name of the WCF Service method plus the word Result.  I have gotten around it by adding the following to the schema part of the datasource definition:

            schema: {
                data: function (data)
                {
                    return jQuery.parseJSON(data.GetRequestSummaryRestResult).Data;
                },
                total: function (data)
                {
                    return jQuery.parseJSON(data.GetRequestSummaryRestResult).Total;
                },
                model: requestsummary
            },

    Is this the expected behaviour and is my solution the best way to deal with it?  Please let me know.
    Thanks
  2. Answer
    Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 02 Feb 2015 Link to this post

    Hi Lance,

    The issue is related to the way data is serialized on the server. Currently the data is not serialized as JSON but as a string.
    Please modify the service so it returns the data in the following format:

    {
        "GetRequestSummaryRestResult": {
            "Data": [
                {
                    "Id": 0.0,
                    "RequestId": 121.0,
                    "Creator": "ElmerFudd",
                    "Recipient": "BugsBunny",
                    "Assignee": null,
                    "RequestType": "EquipmentLoan",
                    "Description": "MobilephonewiththeAndroidoperatingsystem",
                    "CreationDate": "2015-01-14T10: 45: 09",
                    "Status": null,
                    "Comments": null
                },
                {
                    /* etc... */
                }
            ],
            "Total": 11
        }
    }


    Regards,
    Alexander Valchev
    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. Lance
    Lance avatar
    25 posts
    Member since:
    Apr 2013

    Posted 16 Feb 2015 in reply to Alexander Valchev Link to this post

    Thanks so much Alexander!  That was the key.  I was returning a string from my WCF service but I need to return the DataSourceResult object.  Once I did that it worked.
Back to Top