Custom Sort Config

The Predefined Configuration for the Custom Sort function

Custom Sort State

The Custom Sort Config contains a collection of Custom Sort objects:

PropertyDescriptionDefault
CustomSortsCollection of Custom Sort objects.[]

Custom Sort Object

The Custom Sort object is defined as follows:

note

ColumnId is mandatory and either SortedValues or the CustomSortComparerFunction should be used

PropertyDescription
ColumnIdId of Column on which Custom Sort will be applied
CustomSortComparerFunctionStandard comparer function; e valuates 2 cell values and return -1, 0, 1 to set sort order (also receives row to enable lookups on other cell values)
SortedValuesOrder of values by which Column will be sorted; any Column values NOT in this list will be sorted alphabetically AFTER all list values have been sorted
warning

The name of theCustom Sort Comparer User Function is set here and the actual implementation is provided in User Functions section of Adaptable Options

Predefined Config Example

export default {
CustomSort: {
CustomSorts: [
{
ColumnId: 'Rating',
SortedValues: ['AAA', 'AA+', 'AA', 'AA-'], // etc.
},
{
ColumnId: 'Country',
CustomSortComparerFunction: 'country',
},
{
ColumnId: 'currency',
CustomSortComparerFunction: 'currency',
},
],
},
} as PredefinedConfig;
// Adaptable Options
const adaptableOptions: AdaptableOptions = {
userFunctions: [
{
name: 'country',
type: 'CustomSortComparerFunction',
handler(valueA: any, valueB: any, nodeA?: any, nodeB?: any) {
if (valueA === 'United Kingdom') {
return -1;
}
if (valueB === 'United Kingdom') {
return 1;
}
return 0;
},
},
{
name: 'currency',
type: 'CustomSortComparerFunction',
handler(valueA: any, valueB: any, nodeA?: any, nodeB?: any) {
if (valueA === 'USD') {
return -1;
}
if (valueB === 'USD') {
return 1;
}
return 0;
},
},
],

More Information