Configuration

This section describes configuration options used to configure the CustomStore.

byKey

Specifies a custom implementation of the byKey(key, extraOptions) method.

Type:

function

Function parameters:
key:

Object

|

String

|

Number

A key value.

Return Value:

Promise<any> (jQuery or native)

A Promise that is resolved after the item is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.

The method passed to this option should return a Promise.

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();
    },
    . . .
});

cacheRawData

Specifies whether raw data should be saved in the cache. Applies only if loadMode is "raw".

Type:

Boolean

Default Value: true

Data caching allows the CustomStore to decrease the number of data requests. On the downside, cached data and data in your source may become out of sync. If keeping them synchronized is crucial in your scenario, disable data caching by setting the cacheRawData option to false. In this case, the CustomStore will send a request for data on every call of the load, byKey and totalCount functions.

See Also

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

Specifies a custom implementation of the insert(values) method.

Type:

function

Function parameters:
values:

Object

The item to be inserted.

Return Value:

Promise<any> (jQuery or native)

A Promise that is resolved after the item is inserted. It is a native Promise or a jQuery.Promise when you use jQuery.

The method passed to this option should return a Promise.

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

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

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

load

Specifies a custom implementation of the load(options) method.

Type:

function

Function parameters:
options:

LoadOptions

Data processing settings.

Return Value:

Promise<any> (jQuery or native)

A Promise that is resolved after data is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.

This function's implementation has certain specifics depending on the widget in which you use the CustomStore. Refer to the Custom Sources topic of a specific widget for details:

See Also

loadMode

Specifies how data returned by the load function is treated.

Type:

String

Default Value: 'processed'
Accepted Values: 'processed' | 'raw'

Specify this option depending on the behavior you implemented for the load function. If this function sends data shaping options to the server and fetches processed data, then loadMode should be "processed". If the load function simply fetches raw, unprocessed data from the server, set loadMode to "raw". In this case, the raw data will be processed on the client automatically.

See Also

onInserted

A handler for the inserted event.

Type:

function

Function parameters:
values:

Object

The inserted item.

key:

Object

|

String

|

Number

The item's key.

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

The item to be 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.

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

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

The removed item's key.

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

The key of the item to be 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

The updated item's key.

values:

Object

New item values.

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

The key of the item to be updated.

values:

Object

New item values.

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

remove

Specifies a custom implementation of the remove(key) method.

Type:

function

Function parameters:
key:

Object

|

String

|

Number

The key of the item to be removed.

Return Value:

Promise<void> (jQuery or native)

A Promise that is resolved after the item is removed. It is a native Promise or a jQuery.Promise when you use jQuery.

totalCount

Specifies a custom implementation of the totalCount(options) method.

Type:

function

Function parameters:
loadOptions:

Object

Filtering and grouping settings.

Object structure:
filter:

Object

Data filtering settings.

group:

Object

Data grouping settings.

Return Value:

Promise<Number> (jQuery or native)

A Promise that is resolved after data is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.

update

Specifies a custom implementation of the update(key, values) method.

Type:

function

Function parameters:
key:

Object

|

String

|

Number

The key of the item to be updated.

values:

Object

Item fields with their new values.

Return Value:

Promise<any> (jQuery or native)

A Promise that is resolved after the item is updated. It is a native Promise or a jQuery.Promise when you use jQuery.

The method passed to this option should return a Promise.

You can resolve the returned Promise 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();
    }
});

useDefaultSearch

Specifies whether or not the store combines the search expression with the filter expression.

Type:

Boolean

Default Value: undefined

The default value of this option is true if loadMode is "raw", and false if loadMode is "processed".