Custom Sort Comparer

Compare-based User Function which allows users to provide their own Custom Sort implementation.

note

It is a standard 'comparer' type function which evaluates the items and returns -1, 0, 1 to set the sort order.

Definition

handler: AdaptableComparerFunction;

The function is given 2 cell values to compare (as well as both rows to allow you to look up other values in the row if necessary).

It returns -1, 0, 1 in order to sort the list.

This is of type: AdaptableComparerFunction (todo)

Example

// Predefined Config
export default {
CustomSort: {
CustomSorts: [
{
ColumnId: 'Country',
CustomSortComparerFunction: 'UKFirst',
},
{
ColumnId: 'Employee',
CustomSortComparerFunction: 'EmployeeLastName',
},
],
},
} as PredefinedConfig;
// Adaptable Options
const adaptableOptions: AdaptableOptions = {
userFunctions: [
{
name: 'UKFirst',
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: 'EmployeeLastName',
type: 'CustomSortComparerFunction',
handler(valueA: any, valueB: any, nodeA?: any, nodeB?: any) {
if (!valueA || !valueB) {
return 0;
}
const fullName = valueA.split(' ');
const fullNameB = valueB.split(' ');
return fullName[fullName.length - 1] > fullNameB[fullNameB.length - 1]
? 1
: -1;
},
},
],