Methods

This section describes the methods used to access data associated with the CustomStore.

byKey(key)

Gets a data item with a specific key.

Parameters:
key:

Object

|

String

|

Number

The item's key.

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 following example demonstrates how to get an item whose key property value equals 15.

JavaScript
store.byKey(15).done(function(dataItem) {
        // process 'dataItem'
    }).fail(function(error) {
        // handle error
    });

clearRawDataCache()

Deletes data from the cache. Takes effect only if the cacheRawData option is true.

insert(values)

Adds an item to the Store's data.

Parameters:
values:

Object

A new item.

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.

JavaScript
store.insert({
        id: 5,
        name: "item1",
        value: 10
    })
    .done(function(values, key) {
        //'values' contains the inserted item values
        //'key' contains the inserted item key
    })
    .fail(function(error) {
        //handle error
    });
NOTE
If data already contains an object with the same key property value as the object being inserted, the insertion fails.

key()

Gets the key option's value.

Return Value: any

The option's value.

If the Store contains only one key expression, the function returns this expression. If it contains several key expressions, the function returns an array of expressions.

keyOf(obj)

Gets the key value of an item found using its data object.

Parameters:
obj:

Object

The data object.

Return Value: any

The key.

load()

Starts loading data.

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.

load(options)

Starts loading data.

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.

JavaScript
store.load(options)
    .done(function(result) {
        // 'result' contains the loaded data
    })
    .fail(function(error) {
        // handle error
    })

For more information on data shaping options, refer to the Data Layer topic.

off(eventName)

Detaches all event handlers from a single event.

Parameters:
eventName:

String

The event's name.

Return Value:

Object

The object for which this method is called.

See Also

off(eventName, eventHandler)

Detaches a particular event handler from a single event.

Parameters:
eventName:

String

The event's name.

eventHandler:

function

The event's handler.

Return Value:

Object

The object for which this method is called.

See Also

on(eventName, eventHandler)

Subscribes to an event.

Parameters:
eventName:

String

The event's name.

eventHandler:

function

The event's handler.

Return Value:

Object

The object for which this method is called.

Use this method to subscribe to one of the events listed in the Events section.

See Also

on(events)

Subscribes to events.

Parameters:
events:

Object

Events with their handlers: { "eventName1": handler1, "eventName2": handler2, ...}

Return Value:

Object

The object for which this method is called.

Use this method to subscribe to several events with one method call. Available events are listed in the Events section.

See Also

remove(key)

Removes a data item with a specific key.

Parameters:
key:

Object

|

String

|

Number

The key.

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.

JavaScript
store.remove(key)
    .done(function() {
        // handle success
    })
    .fail(function(error) {
        // handle error
    });

totalCount(options)

Gets the total count of items the load() function returns.

Parameters:
obj:

Object

Filtering and grouping options.

Object structure:
filter:

Object

A filtering expression; described in the Filtering section.

group:

Object

A grouping expression; described in the Grouping section.

Return Value:

Promise<Number> (jQuery or native)

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

JavaScript
myStore.totalCount(options)
    .done(function(result) {
        // 'result' contains the item count.
    })
    .fail(function(error) {
        // handle error
    });

update(key, values)

Updates the data item specified by the key.

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:

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.

JavaScript
store.update(key, values)
    .done(function(key, result) {
        // "key" contains the key of the updated item
        // "result" contains the updated item itself
    })
    .fail(function(error) {
        // handle error
    });