Configuration

This section describes configuration options used to configure the CustomStore.

byKey

The user implementation of the byKey(key, extraOptions) method.

Type:

function

Function parameters:
key:

Object

|

String

|

Number

The required key value.

Return Value:

jQuery.Promise

A Promise of the jQuery.Deferred object resolved after the item has been loaded.

The method passed to this option should return either the jQuery.Deferred promise or the jQuery.Deferred compatible object.

JavaScript
var myStore = new DevExpress.data.CustomStore({
    byKey: function(key) {
        var d = new $.Deferred();
        $.get('http://data.example.com/products?id=' + key)
            .done(function (result) {
                d.resolve(result[i]);
            });
        return d.promise();
    },
    . . .
});

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

insert

The user implementation of the insert(values) method.

Type:

function

Function parameters:
values:

Object

An object representing the inserted item.

Return Value:

jQuery.Promise

A Promise of the jQuery.Deferred object resolved after the item has been inserted.

The method passed to this option should return either the jQuery.Deferred promise or the jQuery.Deferred compatible object.

You can resolve the returned jQuery.Deferred with any data. For example, the key of the inserted item.

JavaScript
var store = new DevExpress.data.CustomStore({
    update: function (key, values) {
        var deferred = $.Deferred();
        $.post("http://www.example.com/service/myEntity", values).done(function(data) {
            deferred.resolve(data.key);
        })
        return deferred.promise();
    }
});

inserted

Deprecated

Use the onInserted option instead.

inserting

Deprecated

Use the onInserting option instead.

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"]
}

load

The user implementation of the load(options) method.

Type:

function

Function parameters:
options:

Object

An object specifying data shaping options.

Object structure:
filter:

Object

Filter expression.

sort:

Object

Sort expression.

select:

Object

Select expression.

group:

Object

Group expression.

skip:

Number

The index of the first loaded item.

take:

Number

The number of loaded items.

userData:

Object

A bag for holding user-defined parameters.

requireTotalCount:

Boolean

Specifies whether the function passed to this option should resolve the jQuery.Deferred with the second argument containing the totalCount field.

Return Value:

jQuery.Promise

A Promise of the jQuery.Deferred object resolved after data has been loaded.

The method passed to this option should return either the jQuery.Deferred promise or the jQuery.Deferred compatible object.

If the requireTotalCount field of the options object passed to the function holds true, the function should resolve the jQuery.Deferred with the second argument containing the totalCount field as demonstrated below.

JavaScript
var store = new DevExpress.data.CustomStore({
    load: function (loadOptions) {
        var deferred = $.Deferred();
        result = [item1, item2, item3, . . .];
        if (loadOptions.requireTotalCount === true)
            deferred.resolve(result, { totalCount: result.length });
        else
            deferred.resolve(result);
        return deferred.promise();
    }
});

loaded

Deprecated

Use the onLoaded option instead.

loading

Deprecated

Use the onLoading option instead.

modified

Deprecated

Use the onModified option instead.

modifying

Deprecated

Use the onModifying option instead.

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

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:

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 item to skip.

take:

Number

The number of items to take for the loaded data.

userData:

Object

A bag for holding user-defined parameters.

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.

remove

The user implementation of the remove(key) method.

Type:

function

Function parameters:
key:

Object

|

String

|

Number

The key value of the item being removed.

Return Value:

jQuery.Promise

A Promise of the jQuery.Deferred object resolved after the item has been removed.

The method passed to this option should return either the jQuery.Deferred promise or jQuery.Deferred compatible object.

removed

Deprecated

Use the onRemoved option instead.

removing

Deprecated

Use the onRemoving option instead.

totalCount

The user implementation of the totalCount(options) method.

Type:

function

Function parameters:
loadOptions:

Object

An object specifying filtering and grouping options.

Object structure:
filter:

Object

Data filtering conditions.

group:

Object

Data grouping options.

Return Value:

jQuery.Promise

A Promise of the jQuery.Deferred object resolved after data has been loaded.

The method passed to this option should return either the jQuery.Deferred promise or jQuery.Deferred compatible object.

update

The user implementation of the update(key, values) method.

Type:

function

Function parameters:
key:

Object

|

String

|

Number

The key value of the item being updated.

values:

Object

The object containing new values for the specified item.

Return Value:

jQuery.Promise

A Promise of the jQuery.Deferred object resolved after the item has been updated.

The method passed to this option should return either the jQuery.Deferred promise or the jQuery.Deferred compatible object.

You can resolve the returned jQuery.Deferred with any data. For example, the key of the updated item.

JavaScript
var store = new DevExpress.data.CustomStore({
    update: function (key, values) {
        var deferred = $.Deferred();
        $.ajax({
            url: SERVICE_URL + "/" + encodeURIComponent(key),
            method: "PUT",
            data: values
        }).done(function(){
            deferred.resolve(key);
        });
        return deferred.promise();
    }
});

updated

Deprecated

Use the onUpdated option instead.

updating

Deprecated

Use the onUpdating option instead.