We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Does DataManager support OData v4?

If I provide OData v4 via WEP API 2.2, I wonder that does DataManager support it?


1 Reply

MF Mohammed Farook J Syncfusion Team July 25, 2014 01:35 PM UTC

Hi Kevin

 

Thanks for using Syncfusion Products,

 

Sorry for the inconvenienced.  currently  ejDataManager doesn’t  have support to handle OData V4, but we can achieve your requirement with the help of custom adaptor by extending default ej.ODataAdaptor. please follow the code snippet.

 

We can extend the ej.OdataAdaptor as follows.

 

 

var ODataV4Adaptor = new ej.ODataAdaptor().extend({

    options: {

        count: "$count",

        search: "$search"

    },

    onCount: function (e) {

        return e === true ? "true" : "";

    },

 

 

 

beforeSend function will  be trigger the event before every server request.

 

 

beforeSend: function (dm, request, settings) {  //Will be triggered before every request to server.

        // some services do not support custom header on crossDomain (CORS) request

        if (!dm.dataSource.crossDomain) {

            request.setRequestHeader("DataServiceVersion", "4.0");

            request.setRequestHeader("MaxDataServiceVersion", "4.0");

        }

    },

 

 

 

processResponse is used to process the response to the server

 

processResponse: function (data, ds, query, xhr, request) { //used to process the response from server

        var count;

        if (query && query._requiresCount) {

            count = data['@odata.count'];

            data = data.value;

        }

        return ej.isNullOrUndefined(count) ? data : { result: data, count: count };

    },

 

 

 

 

In the grid load event, we can assign the custom adaptor to the grid datamanager as follow.

 

@(Html.EJ().Grid<Order>("Editing")

        .Datasource(ds => { ds.URL("http://services.odata.org/V4/Northwind/Northwind.svc/Orders/").CrossDomain(true); })//"http://services.odata.org/V4/Northwind/Northwind.svc/Orders/")

        .ClientSideEvents(eve => eve.Load("load").ActionComplete("CompleteHandler").ActionBegin("BeginHandler"))

        .Render())

</div>

 

<script>

 

    refContent = false;

    function load(args) {

        args.model.dataSource.adaptor = new ODataV4Adaptor;

    }

</script>

 

 

Sample Location :  MvcApplication4.zip

 

Please let us know if you have any queries.

 

Thanks with Regards,

J.Mohammed Farook

 

 

 

 


Loader.
Live Chat Icon For mobile
Up arrow icon