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.
Unfortunately, activation email could not send to your email. Please try again.

Does DataManager support OData v4?

Thread ID:

Created:

Updated:

Platform:

Replies:

117024 Jul 22,2014 12:12 AM Jul 25,2014 09:35 AM JavaScript 1
loading
Tags: ejGrid
Kevin
Asked On July 22, 2014 12:12 AM

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


Mohammed Farook J [Syncfusion]
Replied On July 25, 2014 09:35 AM

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

 

 

 

 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;