We have updated Flexmonster Software License Agreement, effective as of September 30, 2024. Learn more about what’s changed.
All documentation
  • API Reference for older versions
  • sortingMethod

    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.

    Parameters

    Parameter/TypeDescription
    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.

    Example

    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;
    });

    Live example

    See also

    Sorting
    setSort()
    getSort()
    sortValues()
    sortFieldsList()