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

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.

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

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 or not 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.

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

lookup

Deprecated

Use byKey instead.

User implementation of the byKey(key, extraOptions) method.

Type: function

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

remove

The user implementation of the remove(key) method.

Type: function
Function parameters:
key: Object

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

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

totalCount

The user implementation of the totalCount(options) method.

Type: function
Function parameters:
loadOptions: 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.

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

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.

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