Configuration

This section describes configuration options used to configure the ODataContext.

beforeSend

A function used to customize a web request before it is sent.

Type: function

The method passed to this option should take on a request object as a parameter, which provides the following fields.

  • async - specifies whether the request is asynchronous or synchronous
  • method - a string representing the request method ("GET", "POST", "PATCH", or "MERGE")
  • url - the request URL
  • params - the additional request parameters
  • payload - the request body; for example, when updating an item, this property holds the value object
  • headers - an object holding the request headers
  • timeout - the request timeout

deserializeDates

Specifies whether or not dates in a response are deserialized.

Type: Boolean

The underlying ODataStore can deserialize dates represented in the ISO8601 format (e.g "2016-07-13T16:05:00.000Z") or format used by Microsoft (e.g., "/Date(1198908717056)/"). In the second case, the ODataStore adds the time-zone offset corresponding to the client time-zone. In the first case, the ODataStore parses the date string without taking a timezone modifier (for example "Z") into account.

entities

Specifies the list of entities to be accessed via the ODataContext.

Type: Object

The object passed to this option should contain Fields whose names equal the corresponding entity names. The ODataContext will create an ODataStore instance for each entity. Therefore, each of these properties takes on an ODataStore configuration object.

JavaScript
var context = new DevExpress.data.ODataContext({
    url: "http://www.example.com/Northwind.svc",
    entities: {
        Categories: { 
            key: "CategoryID", 
            keyType: "Int32" 
        },
        MyCustomers: { 
            name: "Customers",
            key: "CustomerID", 
            keyType: "String" 
        }
    }
});

errorHandler

Specifies the function called if the ODataContext causes an error.

Type: function

The function passed to this option takes on the JavaScript Error object as a parameter.

JavaScript
var context = new DevExpress.data.ODataContext({
    url: "http://www.example.com/Northwind.svc",
    errorHandler: function(error) {
        alert(error.message);
    },
    entities: {
        Categories: {
            key: "CategoryID",
            keyType: "Int32"
        },
        MyCustomers: {
            name: "Customers",
            key: "CustomerID",
            keyType: "String"
        }
    }
});

jsonp

Specifies whether the ODataStore uses the JSONP approach to access non-CORS-compatible remote services.

Type: Boolean
Default Value: false

url

Specifies the URL of the data service being accessed via the current ODataContext.

Type: String

version

Specifies the version of the OData protocol used to interact with the data service.

Type: Number
Default Value: 2
Accepted Values: 2 | 3 | 4
NOTE
If the version option holds 2, ODataContext uses the "MERGE" method to send requests. Otherwise, it uses the "PATCH" method. To override this behavior, use the beforeSend option.

withCredentials

Specifies the value of the withCredentials field of the underlying jqXHR object.

Type: Boolean
Default Value: false

Setting this option to true enables the sending of cookies and authorization headers to foreign domains (CORS-related).