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

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

  • method - a string representing the request method ("GET" or "POST")
  • url - the request URL
  • params - the additional request parameters
  • payload - the request body; for example, when updating an item, this property holds the values object
  • headers - an object holding the request headers

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);
    }
};

inserted

Specifies a function called after a data item has been added.

Type: function
Function parameters:
values: Object

An object representing the inserted item.

key: Object

A key value of the inserted item.

JavaScript
var storeConfig = {
    inserted: function() {
        console.log("A data item has been inserted");
    }
}

inserting

Specifies a function called before a data item is added.

Type: function
Function parameters:
values: Object

An object representing the item being inserted.

JavaScript
var storeConfig = {
    inserting: function() {
        console.log("A data item is being inserted");
    }
}

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 properties within the data associated with the Store.

Type: String|Array

The key configuration option is required if you create a Store for read-write data access. The key property is specified by an appropriate getter. 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 ODataStore key property. The following key types are supported out of the box: String, Int32, Int64, and Guid.

Type: String|Object

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 take on 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"
            }
        }
    }
});

loaded

Specifies a function called after data has been loaded.

Type: function
Function parameters:
result: Array

The loaded data array.

JavaScript
var storeConfig = {
    loaded: function() {
        console.log("A data item has been loaded");
    }
}

loading

Specifies a function called before data is loaded.

Type: function
Function parameters:
loadOptions: Object

An object defining options for the loaded data.

Object structure:
filter: Object

A filter expression for the loaded data.

sort: Object

A sort expression for the loaded data.

select: Object

An expression for selection in the loaded data.

group: Object

An expression for grouping in the loaded data.

skip: Number

The number of items to skip.

take: Number

The number of items to take for the loaded data.

userData: Object

A bag for holding user-defined parameters.

requireTotalCount: Boolean

Specifies whether the event handling function should resolve the jQuery.Deferred with the second argument containing the totalCount field.

JavaScript
var storeConfig = {
    loading: function() {
        console.log("A data item is being loaded");
    }
}

modified

Specifies a function called after data has been modified.

Type: function
JavaScript
var storeConfig = {
    modified: function() {
        console.log("The data has been modified");
    }
}

modifying

Specifies a function called before the data is modified.

Type: function
JavaScript
var storeConfig = {
    modifying: function() {
        console.log("The data is being modified");
    }
}

removed

Specifies a function called after a data item has been removed.

Type: function
Function parameters:
key: Object

A key value of the removed item.

JavaScript
var storeConfig = {
    removed: function() {
        console.log("A data item has been removed");
    }
}

removing

Specifies a function called before a data item is removed.

Type: function
Function parameters:
key: Object

A key value of the item being removed.

JavaScript
var storeConfig = {
    removing: function() {
        console.log("A data item is being removed");
    }
}

updated

Specifies a function called after a data item has been updated.

Type: function
Function parameters:
key: Object

A key value of the updated item.

values: Object

New item values.

JavaScript
var storeConfig = {
    updated: function() {
        console.log("A data item has been updated");
    }
}

updating

Specifies a function called before a data item is updated.

Type: function
Function parameters:
key: Object

A key value of the item being updated.

values: Object

New item values.

JavaScript
var storeConfig = {
    updating: function() {
        console.log("A data item is being updated");
    }
}

url

Specifies the URL of the entity beind accessed via the current ODataStore.

Type: String

version

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

Type: Number
Default Value: 2

withCredentials

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

Type: Boolean
Default Value: false

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