StoreSort

Configs

6

Common

Initial sorters, format is:

{ sorters : [{ field: 'name', ascending: false }, ...] }
// or
{ sorters : ['name', ...] }

Advanced

useLocaleSort: Boolean | String | Object= false

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.

If the app processes many records or many record fields in a loop or similar, be sure to temporarily disable this setting. Otherwise, each change will trigger a sort, which will make the processing slow

ParameterTypeDescription
reapplySortersOnUpdate.fieldsString[]

Fields that reapply sorting when updated

Sorting

reapplySortersOnAdd: Boolean= false

Specify true to sort this store after records are added.

remoteSort: Boolean

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

Class hierarchy

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

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.

If the app processes many records or many record fields in a loop or similar, be sure to temporarily disable this setting. Otherwise, each change will trigger a sort, which will make the processing slow

ParameterTypeDescription
reapplySortersOnUpdate.fieldsString[]

Fields that reapply sorting when updated

Sort, group & filter

isSorted: Booleanreadonly

Is store sorted?

Currently applied sorters

Functions

5

Add a sorting level (a sorter).

ParameterTypeDescription
fieldString | Sorter[] | Sorter | function

Field to sort by. Can also be an array of sorters, or a sorting function, or a sorter config.

ascendingBoolean

Sort order (used only if field specified as string)

Returns: Promise | null -

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.

Returns: Promise | null -

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.

ParameterTypeDescription
sortersSorter[]

An array of sorter config objects

Returns: function

Remove a sorting level (a sorter)

ParameterTypeDescription
fieldString | function

Stop sorting by this field (or sorter function)

Returns: Promise | null -

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' });
ParameterTypeDescription
fieldString | Sorter[] | Sorter | function

Field to sort by. Can also be an array of sorter config objects, or a sorting function, or a sorter config.

ascendingBoolean

Sort order. Applicable when the field is a string (if not specified and already sorted by the field, reverts direction), or an object and ascending property is not specified for the object. true by default. Not applicable when field is a function. ascending is always true in this case.

addBoolean

If true, adds a sorter to the sorters collection. Not applicable when field is an array. In this case always replaces active sorters.

silentBoolean

Set as true to not fire events. UI will not be informed about the changes.

Returns: Promise | null -

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

Fired before sorting

// Adding a listener using the "on" method
storeSort.on('beforeSort', ({ source, sorters, records }) => {

});
ParameterTypeDescription
sourceStore

This Store

sortersSorter[]

Sorter configs

recordsModel[]

Records to sort

Fired after sorting

// Adding a listener using the "on" method
storeSort.on('sort', ({ source, sorters, records }) => {

});
ParameterTypeDescription
sourceStore

This Store

sortersSorter[]

Sorter configs

recordsModel[]

Sorted records

Event handlers

2

Called before sorting

new StoreSort({
    onBeforeSort({ source, sorters, records }) {

    }
});
ParameterTypeDescription
sourceStore

This Store

sortersSorter[]

Sorter configs

recordsModel[]

Records to sort

Called after sorting

new StoreSort({
    onSort({ source, sorters, records }) {

    }
});
ParameterTypeDescription
sourceStore

This Store

sortersSorter[]

Sorter configs

recordsModel[]

Sorted records

Typedefs

1

An immutable object representing a store sorter.

ParameterTypeDescription
fieldString

Field name

fnfunction

A custom sorting function, to be used instead of the "field"

ascendingBoolean

true to sort ascending, false to sort descending