StoreCRUD

Configs

1

Commit changes automatically

Properties

5

Class hierarchy

isStoreCRUD: Boolean= truereadonly
Identifies an object as an instance of StoreCRUD class, or subclass thereof.
isStoreCRUD: Boolean= truereadonlystatic
Identifies an object as an instance of StoreCRUD class, or subclass thereof.

Records

Setting autoCommit to true automatically commits changes to records.

changes: Objectreadonly

Get uncommitted changes as an object of added/modified/removed arrays of records.

// Format:
{
     added: [], // array of Core.data.Model
     modified: [], // array of Core.data.Model
     removed: [] // array of Core.data.Model
}
ParameterTypeDescription
changes.addedModel[]

Records that have been added

changes.modifiedModel[]

Records that have changes to persistable fields

changes.removedModel[]

Records that have been removed

hasChanges: Booleanreadonly

Boolean flag, indicating whether the store has any data changes (its changes accessor returns a non-empty object). Cheaper than changes accessor itself, because it does not clone some internal data structures.

Functions

9

CRUD

Add records to store.

ParameterTypeDescription
recordsModel | Model[] | Object | Object[]

Array of records/data or a single record/data to add to store

silentBoolean

Specify true to suppress events

Returns: Model[] -

Added records

Commits changes, per default only returns changes and resets tracking.

ParameterTypeDescription
silentBoolean

Specify true to suppress events

Returns: Object -

Changes, see changes

Insert records into the store.

ParameterTypeDescription
indexNumber

Index to insert at

recordsModel | Model[] | Object | Object[]

Array of records/data or a single record/data to insert to store

silentBoolean

Specify true to suppress events

Returns: Model[] -

Inserted records

Moves a record, or block of records to another location.

ParameterTypeDescription
recordsModel | Model[]

The record(s) to move.

beforeRecordModel

the record to insert the first record(s) before.

Removes a record from this store. Fires a single remove event passing the removed records.

ParameterTypeDescription
recordsString | String[] | Number | Number[] | Model | Model[]

Record/array of records (or record ids) to remove

silentBoolean

Specify true to suppress events/autoCommit

Returns: Model[] -

Removed records

Removes all records from the store.

If called on a lazy-loaded store, it removes all the loaded records. And if a backend is configured, then those deletions will also be synced with the backend.

ParameterTypeDescription
silentBoolean

Specify true to suppress events

Returns: Boolean -

true unless the action was prevented, in which case it returns false

Reverts all changes in the store (adds removed records back, and removes newly added records).

Records

Resumes automatic commits upon store changes. Will trigger commit if the internal counter is 0.

Suspends automatic commits upon store changes. Can be called multiple times (it uses an internal counter).

Events

9

Fired after adding/inserting record(s). If the record was added to a parent, the isChild flag is set on the event. If it was inserted, event contains index

// Adding a listener using the "on" method
storeCRUD.on('add', ({ source, records, allRecords, parent, index, oldIndex, isChild, isExpand, isMove }) => {

});
ParameterTypeDescription
sourceStore

This Store

recordsModel[]

Added records. In case of tree store, if branch is added, only branch root is returned

allRecordsModel[]

Flat list of all added records. In case of tree store, if branch is added, all new records are returned, not only branch root

parentModel

If due to an appendChild call, this is the parent node added to.

indexNumber

Insertion point in the store's Collection.

oldIndexNumber

Not used for tree stores. The index of the first record moved.

isChildBoolean

Flag which is set to true if the records are added to a parent record

isExpandBoolean

Flag which is set to true if records are added to the store by expanding parent

isMoveObject

An object keyed by the ids of the records which were moved from another position in the store, or from another parent node in the store. The ids of moved records will be property names with a value true.

Fired before records are added to this store by the add or insert. In a tree store, also fired by appendChild and insertChild. The add or insert may be vetoed by returning false from a handler.

// Adding a listener using the "on" method
storeCRUD.on('beforeAdd', ({ source, records, parent }) => {

});
ParameterTypeDescription
sourceStore

This Store

recordsModel[]

The records which are to be added

parentModel

The parent node when using a tree store

Fired before committing changes. Return false from handler to abort commit

// Adding a listener using the "on" method
storeCRUD.on('beforeCommit', ({ source, changes }) => {

});
ParameterTypeDescription
sourceStore

This Store

changesObject

Modification data

Fired before records are removed from this store by the remove or removeAll. Also fired when removing a child record in a tree store using removeChild. The remove may be vetoed by returning false from a handler.

// Adding a listener using the "on" method
storeCRUD.on('beforeRemove', ({ source, records, parent, isMove, removingAll }) => {

});
ParameterTypeDescription
sourceStore

This Store

recordsModel[]

The records which are to be removed.

parentModel

The record from which children are being removed when using a tree store. Only provided when removing a single node.

isMoveBoolean

This flag is true if the child node is being removed by appendChild to be moved within the same tree.

removingAllBoolean

This flag is true if the operation is removing the store's entire data set.

Fired when Data in the store was changed. See change event for the details.

// Adding a listener using the "on" method
storeCRUD.on('change', ({ source, action, record, records, changes }) => {

});
ParameterTypeDescription
sourceStore

This Store

actionremove | removeAll | add | updatemultiple | clearchanges | filter | update | dataset | replace

Name of action which triggered the change. May be one of the options listed above

recordModel

Changed record, for actions that affects exactly one record ('update')

recordsModel[]

Changed records, passed for all actions except 'removeAll'

changesObject

Passed for the 'update' action, info on which record fields changed

Fired after committing changes

// Adding a listener using the "on" method
storeCRUD.on('commit', ({ source, changes }) => {

});
ParameterTypeDescription
sourceStore

This Store

changesObject

Modification data

Data in the store has completely changed, such as by a filter, or sort or load operation.

// Adding a listener using the "on" method
storeCRUD.on('refresh', ({ source, batch, action }) => {

});
ParameterTypeDescription
sourceStore

This Store.

batchBoolean

Flag set to true when the refresh is triggered by ending a batch

actiondataset | sort | clearchanges | filter | create | update | delete | group

Name of action which triggered the change. May be one of the options listed above.

Fired when one or more records are removed

// Adding a listener using the "on" method
storeCRUD.on('remove', ({ source, records, allRecords, parent, index, isChild, isCollapse, isMove }) => {

});
ParameterTypeDescription
sourceStore

This Store

recordsModel[]

Array of removed records. In case of tree store, if branch is removed, only branch root is returned

allRecordsModel[]

Flat array of all removed records. In case of tree store, if branch is removed, all removed records are returned, not only branch root

parentModel

If due to a removeChild call, this is the parent node removed from. Only applicable when removing a single tree node.

indexNumber

Visible index at which record was removed. In case the record was removed from a collapsed branch, -1 is returned. For tree store, this is only provided when removing a single node.

isChildBoolean

Flag which is set to true if the record was removed from a parent record

isCollapseBoolean

Flag which is set to true if records were removed from the store by collapsing parent

isMoveBoolean

Passed as true if the remove was part of a move operation within this Store.

Fired after removing all records

// Adding a listener using the "on" method
storeCRUD.on('removeAll', ({ source }) => {

});
ParameterTypeDescription
sourceStore

This Store

Event handlers

9

Called after adding/inserting record(s). If the record was added to a parent, the isChild flag is set on the event. If it was inserted, event contains index

new StoreCRUD({
    onAdd({ source, records, allRecords, parent, index, oldIndex, isChild, isExpand, isMove }) {

    }
});
ParameterTypeDescription
sourceStore

This Store

recordsModel[]

Added records. In case of tree store, if branch is added, only branch root is returned

allRecordsModel[]

Flat list of all added records. In case of tree store, if branch is added, all new records are returned, not only branch root

parentModel

If due to an appendChild call, this is the parent node added to.

indexNumber

Insertion point in the store's Collection.

oldIndexNumber

Not used for tree stores. The index of the first record moved.

isChildBoolean

Flag which is set to true if the records are added to a parent record

isExpandBoolean

Flag which is set to true if records are added to the store by expanding parent

isMoveObject

An object keyed by the ids of the records which were moved from another position in the store, or from another parent node in the store. The ids of moved records will be property names with a value true.

Called before records are added to this store by the add or insert. In a tree store, also called by appendChild and insertChild. The add or insert may be vetoed by returning false from a handler.

new StoreCRUD({
    onBeforeAdd({ source, records, parent }) {

    }
});
ParameterTypeDescription
sourceStore

This Store

recordsModel[]

The records which are to be added

parentModel

The parent node when using a tree store

Called before committing changes. Return false from handler to abort commit

new StoreCRUD({
    onBeforeCommit({ source, changes }) {

    }
});
ParameterTypeDescription
sourceStore

This Store

changesObject

Modification data

Called before records are removed from this store by the remove or removeAll. Also called when removing a child record in a tree store using removeChild. The remove may be vetoed by returning false from a handler.

new StoreCRUD({
    onBeforeRemove({ source, records, parent, isMove, removingAll }) {

    }
});
ParameterTypeDescription
sourceStore

This Store

recordsModel[]

The records which are to be removed.

parentModel

The record from which children are being removed when using a tree store. Only provided when removing a single node.

isMoveBoolean

This flag is true if the child node is being removed by appendChild to be moved within the same tree.

removingAllBoolean

This flag is true if the operation is removing the store's entire data set.

Called when Data in the store was changed. See change event for the details.

new StoreCRUD({
    onChange({ source, action, record, records, changes }) {

    }
});
ParameterTypeDescription
sourceStore

This Store

actionremove | removeAll | add | updatemultiple | clearchanges | filter | update | dataset | replace

Name of action which triggered the change. May be one of the options listed above

recordModel

Changed record, for actions that affects exactly one record ('update')

recordsModel[]

Changed records, passed for all actions except 'removeAll'

changesObject

Passed for the 'update' action, info on which record fields changed

Called after committing changes

new StoreCRUD({
    onCommit({ source, changes }) {

    }
});
ParameterTypeDescription
sourceStore

This Store

changesObject

Modification data

Data in the store has completely changed, such as by a filter, or sort or load operation.

new StoreCRUD({
    onRefresh({ source, batch, action }) {

    }
});
ParameterTypeDescription
sourceStore

This Store.

batchBoolean

Flag set to true when the refresh is triggered by ending a batch

actiondataset | sort | clearchanges | filter | create | update | delete | group

Name of action which triggered the change. May be one of the options listed above.

Called when one or more records are removed

new StoreCRUD({
    onRemove({ source, records, allRecords, parent, index, isChild, isCollapse, isMove }) {

    }
});
ParameterTypeDescription
sourceStore

This Store

recordsModel[]

Array of removed records. In case of tree store, if branch is removed, only branch root is returned

allRecordsModel[]

Flat array of all removed records. In case of tree store, if branch is removed, all removed records are returned, not only branch root

parentModel

If due to a removeChild call, this is the parent node removed from. Only applicable when removing a single tree node.

indexNumber

Visible index at which record was removed. In case the record was removed from a collapsed branch, -1 is returned. For tree store, this is only provided when removing a single node.

isChildBoolean

Flag which is set to true if the record was removed from a parent record

isCollapseBoolean

Flag which is set to true if records were removed from the store by collapsing parent

isMoveBoolean

Passed as true if the remove was part of a move operation within this Store.

Called after removing all records

new StoreCRUD({
    onRemoveAll({ source }) {

    }
});
ParameterTypeDescription
sourceStore

This Store