Configuration

This section describes the configuration options used to configure the ODataStore.

beforeSend

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 or not dates found in the response are deserialized.

Type:

Boolean

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.

errorHandler

Specifies the function called when the Store causes an error.

Type:

function

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

JavaScript
var storeConfig = {
    errorHandler: function(error) {
        console.log(error.message);
    }
};

fieldTypes

Specifies the types of data fields. Accepts the following types: "String", "Int32", "Int64", "Boolean", "Single", "Decimal" and "Guid".

Type:

Object

Default Value: {}

Set this option if you are going to filter data. An object assigned to it should list data fields and their types as field-value pairs. You can also use this option instead of keyType to specify the type of the key property.

JavaScript
var store = new DevExpress.data.ODataStore({
    url: "/url/to/the/service",
    key: "ProductID",
    fieldTypes: {
        ProductID: "Guid",
        ProductName: "String",
        ProductPrice: "Int32"
    }
});

You can configure this option in an ASP.NET MVC Control as follows:

Razor C#
Razor VB
@(Html.DevExtreme().WidgetName()
    .DataSource(d => d.OData()
        .Url("/url/to/the/service")
        .Key("ProductID")
        .FieldTypes(new Dictionary<string, EdmType> {
            { "ProductID", EdmType.Guid },
            { "ProductName", EdmType.String },
            { "ProductPrice", EdmType.Int32 }
        })
    )
)
@(Html.DevExtreme().WidgetName() _
    .DataSource(Function(ds)
        Return ds.OData() _
                 .Url("/url/to/the/service")
                 .Key("ProductID") _
                 .FieldTypes(New Dictionary(Of String, EdmType) From {
                     { "ProductID", EdmType.Guid },
                     { "ProductName", EdmType.String },
                     { "ProductPrice", EdmType.Int32 }
                 })
    End Function)
)

jsonp

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

Type:

Boolean

Default Value: false

key

Specifies the key property or properties.

Type:

String

|

Array<String>

The key configuration option is required if you create a Store for read-write data access. An appropriate getter specifies the key property. If you need to specify a compound key property, assign an array of getters to this option.

The following example demonstrates how to set id and code key properties:

JavaScript
var storeConfig = {
    key: ["id", "code"]
}

keyType

Specifies the type of the key property or properties.

Type:

String

|

Object

Accepted Values: 'String' | 'Int32' | 'Int64' | 'Guid' | 'Boolean' | 'Single' | 'Decimal'

If a key expression is a simple getter, the keyType option takes on a string value.

JavaScript
var store = new DevExpress.data.ODataStore({
    url: "/url/to/service",
    key: "ProductID",
    keyType: "Guid"
});

If you specified a composite key, the keyType option should apply an object providing corresponding properties for each key expression, as demonstrated in the following example:

JavaScript
var context = new DevExpress.data.ODataContext({
    url: "http://www.example.com/Northwind.svc",
    entities: {
        Products: {
            key: [ "ProductID", "ProductCode" ],
            keyType: {
                ProductID: "Guid",
                ProductCode: "Int32"
            }
        }
    }
});

When specifying this option in an ASP.NET MVC Control, use the EdmType enum that has the following values: Int32, Int64, Guid, String, Boolean, Single and Decimal.

See Also

onInserted

A handler for the inserted event.

Type:

function

Function parameters:
values:

Object

An object representing the inserted item.

key:

Object

|

String

|

Number

A key value of the inserted item.

Assign a function to perform a custom action after a data item is added.

onInserting

A handler for the inserting event.

Type:

function

Function parameters:
values:

Object

An object representing the item being inserted.

Assign a function to perform a custom action before a data item is added.

onLoaded

A handler for the loaded event.

Type:

function

Function parameters:
result:

Array<any>

The loaded data array.

Assign a function to perform a custom action after data is loaded.

onLoading

A handler for the loading event.

Type:

function

Function parameters:
loadOptions:

LoadOptions

An object containing data processing settings.

Assign a function to perform a custom action before data is loaded.

onModified

A handler for the modified event.

Type:

function

Assign a function to perform a custom action after data is modified.

onModifying

A handler for the modifying event.

Type:

function

Assign a function to perform a custom action before the data is modified.

onRemoved

A handler for the removed event.

Type:

function

Function parameters:
key:

Object

|

String

|

Number

A key value of the removed item.

Assign a function to perform a custom action after a data item has been removed.

onRemoving

A handler for the removing event.

Type:

function

Function parameters:
key:

Object

|

String

|

Number

A key value of the item being removed.

Assign a function to perform a custom action before a data item is removed.

onUpdated

A handler for the updated event.

Type:

function

Function parameters:
key:

Object

|

String

|

Number

A key value of the updated item.

values:

Object

New values for the updated item.

Assign a function to perform a custom action after a data item has been updated.

onUpdating

A handler for the updating event.

Type:

function

Function parameters:
key:

Object

|

String

|

Number

A key value of the item being updated.

values:

Object

New values for the item being updated.

Assign a function to perform a custom action before a data item is updated.

url

Specifies the URL of the OData entity to access.

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, ODataStore uses the "MERGE" method to send requests. Otherwise, it uses the "PATCH" method. To override this behavior, use the beforeSend option.

withCredentials

Specifies whether to send cookies and authorization headers to foreign domains in a cross-origin request.

Type:

Boolean

Default Value: false

This option's value is passed to the underlying jqXHR object.