DevExtreme Vue - CustomStore Props

This section describes options that configure the CustomStore.

byKey

Specifies a custom implementation of the byKey(key) 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 data item is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    // ...
    byKey: function (key) {
        var d = new $.Deferred();
        $.get("http://mydomain.com/MyDataService?id=" + key)
            .done(function (dataItem) {
                d.resolve(dataItem);
            });
        return d.promise();
    }
});
Angular
TypeScript
import { ..., Inject } from '@angular/core';
import CustomStore from "devextreme/data/custom_store";
import { Http, HttpModule } from '@angular/http';
import 'rxjs/add/operator/toPromise';
// ...
export class AppComponent {
    store: CustomStore;
    constructor(@Inject(Http) http: Http) {
        this.store = new CustomStore({
            // ...
            byKey: (key) => {
                return http.get("http://mydomain.com/MyDataService?id=" + key)
                    .toPromise()
                    .then(response => {
                        return {
                            data: response.json().data
                        };
                    });
            }
        });
    }
}
@NgModule({
    imports: [
        // ...
        HttpModule 
    ],
    // ...
})

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 that is executed when the store throws an error.

Type:

Function

This function accepts a JavaScript Error object as the parameter.

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    // ...
    errorHandler: function (error) {
        console.log(error.message);
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            // ...
            errorHandler: function (error) {
                console.log(error.message);
            }
        })
    }
}

insert

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

Type:

Function

Function parameters:
values:

Object

The data item to be inserted.

Return Value:

Promise<any> (jQuery or native)

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

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    // ...
    insert: function (values) {
        return $.ajax({
            url: "http://mydomain.com/MyDataService/myEntity",
            method: "POST",
            data: values
        })
    }
});
Angular
TypeScript
import { ..., Inject } from '@angular/core';
import CustomStore from "devextreme/data/custom_store";
import { Http, HttpModule } from '@angular/http';
import 'rxjs/add/operator/toPromise';
// ...
export class AppComponent {
    store: CustomStore;
    constructor(@Inject(Http) http: Http) {
        this.store = new CustomStore({
            // ...
            insert: (values) => {
                return http.post("http://mydomain.com/MyDataService/myEntity", values)
                    .toPromise();
            }
        });
    }
}
@NgModule({
    imports: [
        // ...
        HttpModule 
    ],
    // ...
})

key

Specifies the key property (or properties) used to access data items.

Type:

String

|

Array<String>

In the following example, the ProductID and ProductCode properties are specified as key properties:

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    // ...
    key: ["ProductID", "ProductCode"]
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            // ...
            key: ["ProductID", "ProductCode"]
        })
    }
}

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 function that is executed after a data item is added to the store.

Type:

Function

Function parameters:
values:

Object

The added data item.

key:

Object

|

String

|

Number

The item's key.

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    onInserted: function (values, key) {
        // Your code goes here
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            onInserted: function (values, key) {
                // Your code goes here
            }
        })
    }
}

onInserting

A function that is executed before a data item is added to the store.

Type:

Function

Function parameters:
values:

Object

The data item to be added.

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    onInserting: function (values) {
        // Your code goes here
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            onInserting: function (values) {
                // Your code goes here
            }
        })
    }
}

onLoaded

A function that is executed after data is loaded to the store.

Type:

Function

Function parameters:
result:

Array<any>

The loaded data.

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    onLoaded: function (result) {
        // Your code goes here
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            onLoaded: function (result) {
                // Your code goes here
            }
        })
    }
}

onLoading

A function that is executed before data is loaded to the store.

Type:

Function

Function parameters:
loadOptions:

LoadOptions

Data processing settings.

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    onLoading: function (loadOptions) {
        // Your code goes here
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            onLoading: function (loadOptions) {
                // Your code goes here
            }
        })
    }
}

onModified

A function that is executed after a data item is added, updated, or removed from the store.

Type:

Function

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    onModified: function () {
        // Your code goes here
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            onModified: function () {
                // Your code goes here
            }
        })
    }
}

onModifying

A function that is executed before a data item is added, updated, or removed from the store.

Type:

Function

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    onModifying: function () {
        // Your code goes here
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            onModifying: function () {
                // Your code goes here
            }
        })
    }
}

onRemoved

A function that is executed after a data item is removed from the store.

Type:

Function

Function parameters:
key:

Object

|

String

|

Number

The removed data item's key.

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    onRemoved: function (key) {
        // Your code goes here
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            onRemoved: function (key) {
                // Your code goes here
            }
        })
    }
}

onRemoving

A function that is executed before a data item is removed from the store.

Type:

Function

Function parameters:
key:

Object

|

String

|

Number

The key of the data item to be removed.

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    onRemoving: function (key) {
        // Your code goes here
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            onRemoving: function (key) {
                // Your code goes here
            }
        })
    }
}

onUpdated

A function that is executed after a data item is updated in the store.

Type:

Function

Function parameters:
key:

Object

|

String

|

Number

The updated data item's key.

values:

Object

Updated values.

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    onUpdated: function (key, values) {
        // Your code goes here
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            onUpdated: function (key, values) {
                // Your code goes here
            }
        })
    }
}

onUpdating

A function that is executed before a data item is updated in the store.

Type:

Function

Function parameters:
key:

Object

|

String

|

Number

The key of the data item to be updated.

values:

Object

New values for the data item fields.

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    onUpdating: function (key, values) {
        // Your code goes here
    }
});
Angular
TypeScript
import CustomStore from "devextreme/data/custom_store";
// ...
export class AppComponent {
    store: CustomStore;
    constructor() {
        this.store = new CustomStore({
            onUpdating: function (key, values) {
                // Your code goes here
            }
        })
    }
}

remove

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

Type:

Function

Function parameters:
key:

Object

|

String

|

Number

The key of the data item to be removed.

Return Value:

Promise<void> (jQuery or native)

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

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    // ...
    remove: function (key) {
        return $.ajax({
            url: "http://mydomain.com/MyDataService/myEntity" + encodeURIComponent(key),
            method: "DELETE",
        })
    }
});
Angular
TypeScript
import { ..., Inject } from '@angular/core';
import CustomStore from "devextreme/data/custom_store";
import { Http, HttpModule } from '@angular/http';
import 'rxjs/add/operator/toPromise';
// ...
export class AppComponent {
    store: CustomStore;
    constructor(@Inject(Http) http: Http) {
        this.store = new CustomStore({
            // ...
            remove: (key) => {
                return http.delete("http://mydomain.com/MyDataService" + encodeURIComponent(key))
                    .toPromise();
            }
        });
    }
}
@NgModule({
    imports: [
        // ...
        HttpModule 
    ],
    // ...
})

totalCount

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

Type:

Function

Function parameters:
loadOptions:

Object

Filtering and grouping settings.

Object structure:
Name Type Description
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 data item to be updated.

values:

Object

An object with new values for the data item.

Return Value:

Promise<any> (jQuery or native)

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

jQuery
JavaScript
var store = new DevExpress.data.CustomStore({
    // ...
    update: function (key, values) {
        return $.ajax({
            url: "http://mydomain.com/MyDataService/myEntity" + encodeURIComponent(key),
            method: "PUT",
            data: values
        })
    }
});
Angular
TypeScript
import { ..., Inject } from '@angular/core';
import CustomStore from "devextreme/data/custom_store";
import { Http, HttpModule } from '@angular/http';
import 'rxjs/add/operator/toPromise';
// ...
export class AppComponent {
    store: CustomStore;
    constructor(@Inject(Http) http: Http) {
        this.store = new CustomStore({
            // ...
            update: (key, values) => {
                return http.put("http://mydomain.com/MyDataService/myEntity" + encodeURIComponent(key), values)
                    .toPromise();
            }
        });
    }
}
@NgModule({
    imports: [
        // ...
        HttpModule 
    ],
    // ...
})

useDefaultSearch

Specifies whether the store combines the search and filter expressions. Defaults to true if the loadMode is "raw" and false if it is "processed".

Type:

Boolean

Default Value: undefined