sortingMethod(uniqueName: String, compareFunction: Function)
[starting from version: 2.6]
Defines custom sorting for field members. For more details about defining custom sorting, refer to the Sorting tutorial.
Parameter/Type | Description |
---|---|
uniqueName String | The unique name of the field to which the sorting is applied. |
compareFunction Function | Defines the sort order. The input parameters are the same as for compareFunction of Array.sort() method. |
The following code sets custom sorting where members that begin with a specific letter (e.g., "F"
) are put first, while all other members remain in alphabetical order:
const letterToPutFirst = "F";
pivot.sortingMethod("Contact Last Name", function(a, b) {
if (a.at(0) == letterToPutFirst && b.at(0) == letterToPutFirst)
return a > b ? 1 : -1;
if (a.at(0) == letterToPutFirst)
return -1;
if (b.at(0) == letterToPutFirst)
return 1;
return a > b ? 1 : -1;
});