Skip to main content
Version: 8.1

sortDataset

This function is used by Ignition's Expression language.

Description​

Takes a dataset and returns a sorted version of dataset. The sort order is determined by a single column. This works on numeric, as well as alphanumeric columns. When sorting alphanumerically, contiguous numbers are treated as a single number: you may recognize this as a "natural sort".

Sort Order​

The table below represents an example of how alphanumeric values are sorted by the function (assuming a natural sort). Where Raw Column Values represents an initial set of values, and the Sorted columns show how the function sorts in Ascending and Descending order.

Raw Column ValuesSorted - AscendingSorted - Descending
a1a1Z3
A1Z3A1
a4a22a22
a7z9z3a1
a22A1z3
a77z4a77z4a7z9
a77z99a77z99a4
Z3a4a77z99
z3a7z9a77z4

Some caveats to be aware of:

  • Null values for string columns are sorted first
  • Null values for numeric columns are sorted last
  • Casing is not used as a method of sorting. If the only difference between two cells is the casing, then the resulting order depends largely on where the cells were in the raw column.

Syntax (index)​

sortDataset(dataset, colIndex, [ascending], [naturalOrdering])

  • Parameters

    • DataSet dataset - The starting dataset.

    • Integer colIndex - The index of the column to sort on.

    • Boolean ascending - A flag indicating whether or not to sort ascending. Defaults to true. [optional]

    • Boolean naturalOrdering - A flag indicating the ordering method. True for natural, false for alphabetical. Defaults to true. [optional]

  • Results

    • DataSet - A sorted dataset

Syntax (name)​

sortDataset(dataset, colName, [ascending], [naturalOrdering])

  • Parameters

    • DataSet dataset - The starting dataset.

    • String colName- The name of the column to sort on.

    • Boolean ascending - A flag indicating whether or not to sort ascending. Defaults to true. [optional]

    • Boolean naturalOrdering - A flag indicating the ordering method. True for natural, false for alphabetical. Defaults to true. [optional]

  • Results

    • DataSet - A sorted dataset

Examples​

Code Snippet
sortDataset(dataset, 0, true) // returns a Dataset sorted ascending on column 0.
Code Snippet
sortDataset(dataset, "Column 1", false) // returns a Dataset sorted descending on the column named "Column 1".