StoreSort
Configs
6
Configs
6Common
Initial sorters, format is:
{ sorters : [{ field: 'name', ascending: false }, ...] }
// or
{ sorters : ['name', ...] }
Advanced
Use localeCompare() when sorting, which lets the browser sort in a locale specific order. Set to true,
a locale string or a locale config to enable.
Enabling this has big negative impact on sorting
performance. For more info on localeCompare(), see MDN.
Examples:
const store = new Store({
// Swedish sorting
useLocaleSort : 'sv-SE'
});
const store = new Store({
// Swedish sorting with custom casing order
useLocaleSort : {
locale : 'sv-SE',
caseFirst : 'upper'
}
});
Can also be configured on a per-sorter basis:
store.sort({ field: 'name', useLocaleSort : 'sv-SE' });
Filtering
Specify true to reapply sorting when a record is updated in the store. You can also provide an array
of field names, to only trigger sort when certain data fields are updated.
| Parameter | Type | Description |
|---|---|---|
reapplySortersOnUpdate.fields | String[] | Fields that reapply sorting when updated |
Sorting
Specify true to sort this store after records are added.
Set this to true to activate remote sorting in this Store. This makes it possible to use the built-in
sorting features of the Store and corresponding UI functionality, without using local data.
For a non-AjaxStore, data will be requested by the Store by calling a by the app implemented requestData function. Data can also be provided by listening to the requestData event, and updating the data property with new data.
For AjaxStore, data will be loaded via the configured readUrl.
The name of the parameter to use to pass any sorters when loading data remotely.
Note: When this is set, sorters must be defined using a field name and an ascending flag, not a sort function.
Properties
5
Properties
5Class hierarchy
Filtering
Specify true to reapply sorting when a record is updated in the store. You can also provide an array
of field names, to only trigger sort when certain data fields are updated.
| Parameter | Type | Description |
|---|---|---|
reapplySortersOnUpdate.fields | String[] | Fields that reapply sorting when updated |
Sort, group & filter
Is store sorted?
Currently applied sorters
Functions
5
Functions
5Add a sorting level (a sorter).
| Parameter | Type | Description |
|---|---|---|
field | String | Sorter[] | Sorter | function | Field to sort by. Can also be an array of sorters, or a sorting function, or a sorter config. |
ascending | Boolean | Sort order (used only if field specified as string) |
If sortParamName is set on store, this method returns Promise
which is resolved after data is loaded from remote server, otherwise it returns null
Removes all sorters, turning store sorting off.
If sortParamName is set on store, this method returns Promise
which is resolved after data is loaded from remote server, otherwise it returns null
Creates a function used with Array#sort when sorting the store. Override to use your own custom sorting logic.
| Parameter | Type | Description |
|---|---|---|
sorters | Sorter[] | An array of sorter config objects |
Remove a sorting level (a sorter)
| Parameter | Type | Description |
|---|---|---|
field | String | function | Stop sorting by this field (or sorter function) |
If sortParamName is set on store, this method returns Promise
which is resolved after data is loaded from remote server, otherwise it returns null
Sort records, either by replacing current sorters or by adding to them.
A sorter can specify a custom sorting function which will be called with arguments (recordA, recordB).
Works in the same way as a standard array sorter, except that returning null triggers the stores
normal sorting routine.
// single sorter
store.sort('age');
// single sorter as object, descending order
store.sort({ field : 'age', ascending : false });
// multiple sorters
store.sort(['age', 'name']);
// using custom sorting function
store.sort((recordA, recordB) => {
// apply custom logic, for example:
return recordA.name.length < recordB.name.length ? -1 : 1;
});
// using locale specific sort (slow)
store.sort({ field : 'name', useLocaleSort : 'sv-SE' });
| Parameter | Type | Description |
|---|---|---|
field | String | Sorter[] | Sorter | function | Field to sort by. Can also be an array of sorter config objects, or a sorting function, or a sorter config. |
ascending | Boolean | Sort order.
Applicable when the |
add | Boolean | If |
silent | Boolean | Set as true to not fire events. UI will not be informed about the changes. |
If sortParamName is set on store, this method returns Promise
which is resolved after data is loaded from remote server, otherwise it returns null
Events
2
Events
2Event handlers
2
Event handlers
2Typedefs
1
Typedefs
1An immutable object representing a store sorter.
| Parameter | Type | Description |
|---|---|---|
field | String | Field name |
fn | function | A custom sorting function, to be used instead of the "field" |
ascending | Boolean |
|