This is a migrated thread and some comments may be shown as answers.

WCF Datasource for MVVM Grid with server paging

2 Answers 52 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Lance
Top achievements
Rank 1
Lance asked on 30 Jan 2015, 12:28 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 02 Feb 2015, 03:40 PM
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!
 
0
Lance
Top achievements
Rank 1
answered on 17 Feb 2015, 04:31 AM
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.
Tags
Data Source
Asked by
Lance
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Lance
Top achievements
Rank 1
Share this question
or