StoreCRUD
Configs
1
Configs
1Commit changes automatically
Properties
5
Properties
5Class hierarchy
Records
Setting autoCommit to true automatically commits changes to records.
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
}
| Parameter | Type | Description |
|---|---|---|
changes.added | Model[] | Records that have been added |
changes.modified | Model[] | Records that have changes to persistable fields |
changes.removed | Model[] | Records that have been removed |
Functions
9
Functions
9CRUD
Add records to store.
| Parameter | Type | Description |
|---|---|---|
records | Model | Model[] | Object | Object[] | Array of records/data or a single record/data to add to store |
silent | Boolean | Specify |
Added records
Commits changes, per default only returns changes and resets tracking.
| Parameter | Type | Description |
|---|---|---|
silent | Boolean | Specify |
Changes, see changes
Insert records into the store.
| Parameter | Type | Description |
|---|---|---|
index | Number | Index to insert at |
records | Model | Model[] | Object | Object[] | Array of records/data or a single record/data to insert to store |
silent | Boolean | Specify |
Inserted records
Moves a record, or block of records to another location.
| Parameter | Type | Description |
|---|---|---|
records | Model | Model[] | The record(s) to move. |
beforeRecord | Model | the record to insert the first record(s) before. |
Removes a record from this store. Fires a single remove event passing the removed records.
| Parameter | Type | Description |
|---|---|---|
records | String | String[] | Number | Number[] | Model | Model[] | Record/array of records (or record ids) to remove |
silent | Boolean | Specify |
Removed records
Removes all records from the store.
| Parameter | Type | Description |
|---|---|---|
silent | Boolean | Specify |
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
Events
9Fired 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
records | Model[] | Added records. In case of tree store, if branch is added, only branch root is returned |
allRecords | Model[] | Flat list of all added records. In case of tree store, if branch is added, all new records are returned, not only branch root |
parent | Model | If due to an appendChild call, this is the parent node added to. |
index | Number | Insertion point in the store's Collection. |
oldIndex | Number | Not used for tree stores. The index of the first record moved. |
isChild | Boolean | Flag which is set to |
isExpand | Boolean | Flag which is set to |
isMove | Object | 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 |
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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
records | Model[] | The records which are to be added |
parent | Model | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
changes | Object | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
records | Model[] | The records which are to be removed. |
parent | Model | The record from which children are being removed when using a tree store. Only provided when removing a single node. |
isMove | Boolean | This flag is |
removingAll | Boolean | This flag is |
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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
action | remove | removeAll | add | updatemultiple | clearchanges | filter | update | dataset | replace | Name of action which triggered the change. May be one of the options listed above |
record | Model | Changed record, for actions that affects exactly one record ( |
records | Model[] | Changed records, passed for all actions except |
changes | Object | Passed for the |
Fired after committing changes
// Adding a listener using the "on" method
storeCRUD.on('commit', ({ source, changes }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
changes | Object | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store. |
batch | Boolean | Flag set to |
action | dataset | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
records | Model[] | Array of removed records. In case of tree store, if branch is removed, only branch root is returned |
allRecords | Model[] | Flat array of all removed records. In case of tree store, if branch is removed, all removed records are returned, not only branch root |
parent | Model | If due to a removeChild call, this is the parent node removed from. Only applicable when removing a single tree node. |
index | Number | 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. |
isChild | Boolean | Flag which is set to |
isCollapse | Boolean | Flag which is set to |
isMove | Boolean | Passed as |
Event handlers
9
Event handlers
9Called 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
records | Model[] | Added records. In case of tree store, if branch is added, only branch root is returned |
allRecords | Model[] | Flat list of all added records. In case of tree store, if branch is added, all new records are returned, not only branch root |
parent | Model | If due to an appendChild call, this is the parent node added to. |
index | Number | Insertion point in the store's Collection. |
oldIndex | Number | Not used for tree stores. The index of the first record moved. |
isChild | Boolean | Flag which is set to |
isExpand | Boolean | Flag which is set to |
isMove | Object | 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 |
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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
records | Model[] | The records which are to be added |
parent | Model | The parent node when using a tree store |
Called before committing changes. Return false from handler to abort commit
new StoreCRUD({
onBeforeCommit({ source, changes }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
changes | Object | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
records | Model[] | The records which are to be removed. |
parent | Model | The record from which children are being removed when using a tree store. Only provided when removing a single node. |
isMove | Boolean | This flag is |
removingAll | Boolean | This flag is |
Called when Data in the store was changed. See change event for the details.
new StoreCRUD({
onChange({ source, action, record, records, changes }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
action | remove | removeAll | add | updatemultiple | clearchanges | filter | update | dataset | replace | Name of action which triggered the change. May be one of the options listed above |
record | Model | Changed record, for actions that affects exactly one record ( |
records | Model[] | Changed records, passed for all actions except |
changes | Object | Passed for the |
Called after committing changes
new StoreCRUD({
onCommit({ source, changes }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
changes | Object | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store. |
batch | Boolean | Flag set to |
action | dataset | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |
records | Model[] | Array of removed records. In case of tree store, if branch is removed, only branch root is returned |
allRecords | Model[] | Flat array of all removed records. In case of tree store, if branch is removed, all removed records are returned, not only branch root |
parent | Model | If due to a removeChild call, this is the parent node removed from. Only applicable when removing a single tree node. |
index | Number | 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. |
isChild | Boolean | Flag which is set to |
isCollapse | Boolean | Flag which is set to |
isMove | Boolean | Passed as |
Called after removing all records
new StoreCRUD({
onRemoveAll({ source }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Store | This Store |