Skip to main content
Version: 7.9

system.dataset.sort

This function is used in Python Scripting.

Description

Sorts a dataset and returns the sorted dataset. This works on numeric, as well as alphanumeric columns. It will go character by character, going from 0-9, A-Z, a-z.

Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax

system.dataset.sort(dataset, keyColumn [, ascending])

Parameters

TypeParameterDescription
DatasetdatasetThe dataset to sort.
intkeyColumnThe index or column name of the column to sort on.
booleanascendingTrue for ascending order, False for descending order. If omitted, ascending order will be used.[ optional ]
PyObjectvalueThe new value for the specified row/column.

Returns

Dataset - A new sorted dataset.

Scope

All

Code Examples

Example 1
# This code will take the data in a table component, sort it based on the column with index 1,
# and then reinsert the sorted data into the same table.

data = event.source.parent.getComponent('Table').data
newData = system.dataset.sort(data, 1)
event.source.parent.getComponent('Table').data = newData
Example 2
# This code will create a dataset in scripting, and then sort it based on the name of one of the columns.
# It then inserts the sorted dataset into a table component.

headers = ["City", "Population", "Timezone", "GMTOffset"]
data = []

data.append(["New York", 8363710, "EST", -5])
data.append(["Los Angeles", 3833995, "PST", -8])
data.append(["Chicago", 2853114, "CST", -6])
data.append(["Houston", 2242193, "CST", -6])
data.append(["Phoenix", 1567924, "MST", -7])

cities = system.dataset.toDataSet(headers, data)
newData = system.dataset.sort(cities, "City")
event.source.parent.getComponent('Table').data = newData