Configuration

This section describes configuration options used to configure the ODataContext.

beforeSend

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

Type:

function

Function parameters:
options:

Object

The request parameters.

Object structure:
url:

String

The request URL.

async:

Boolean

Specifies whether the request is asynchronous or synchronous.

method:

String

The request method ("GET", "POST", "PATCH", or "MERGE").

timeout:

Number

The request timeout.

params:

Object

The additional request parameters.

payload:

Object

The request body; for example, when updating an item, this property holds the values object.

headers:

Object

The request headers.

deserializeDates

Specifies whether stores in the ODataContext serialize/parse date-time values.

Type:

Boolean

Stores can parse date-time values in ISO8601 format (for example, "2016-07-13T16:05:00.000Z") or Microsoft format (for instance, "/Date(1198908717056)/"). In the first case, the store ignores the timezone modifier (usually Z) when parsing the value. In the second case, the store adds the time-zone offset to the value according to the client's time-zone.

NOTE

Disabling deserialization may cause filtering issues in widgets bound to the ODataStore. When deserialization is disabled in the store, date-time strings are converted to Date objects at the widget level. When filtering, the widget reverts an entered date-time value to a string based on the dateSerializationFormat option's value and passes the string to the ODataStore for further processing. OData does not support strings which cause filtering to fail.

To prevent these issues, the store's deserializeDates option should be set to true or set the widget's dateSerializationFormat option to null.

entities

Specifies the list of entities to be accessed with 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 to use JSONP to access CORS-incompatiable 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).