User Manual

GETTING STARTED


MODULES AND PLATFORM


APPENDIX


TUTORIALS & HELPFUL TRICKS


STRATEGIC PARTNER LINKS

Sepasoft - MES Modules
Cirrus Link - MQTT Modules

RESOURCES

Inductive University
Ignition Demo Project
Knowledge Base Articles
Forum
IA Support
SDK Documentation
SDK Examples

ALL USER MANUAL VERSIONS

Ignition 8.1
Ignition 7.9
Ignition 7.8

Deprecated Pages

Employees

Sign In

Skip to end of metadata
Go to start of metadata

This function is used in Python Scripting.

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". 

Note: Datasets are immutable, which means they cannot be directly modified once created. Instead, this scripting function returns a new dataset with some modification applied, which must be assigned to a variable to be used. See Altering a Dataset.

Alphanumeric Sort 

The table below represents an example of how alphanumeric values are sorted by the function. 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
a22A1z3
Z3a4a77z99
z3a7z9a77z4
a4a22a22
a77z4a77z4a7z9
a77z99a77z99a4
a7z9Z3a1
A1z3A1
Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax

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

  • Parameters

Dataset dataset - The dataset to sort.

Integer | String keyColumn - The index of the column to sort on.

Boolean ascending - True for ascending order, False for descending order. If omitted, ascending order will be used. [optional]


The following feature is new in Ignition version 8.0.16
Click here to check out the other new features

Boolean naturalOrdering - True for natural ordering, False for alphabetical ordering. Ignored if the sort column is a directly sortable data type. If omitted, defaults to True (natural ordering). [optional]

  • Returns

Dataset - A new sorted dataset.

  • Scope

Gateway, Vision Client, Perspective Session



Code Examples
Code Snippet
# This code will take the data in a Vision 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
Code Snippet
# 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.

# Initialize column headers and empty data list
headers = ["City", "Population", "Timezone", "GMTOffset"]
data = []
# Add rows, one by one, into data list
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])
# Convert headers and data lists into dataset
cities = system.dataset.toDataSet(headers, data)
# Sort the resulting dataset by city name
newData = system.dataset.sort(cities, "City")
# Write final dataset to a table
event.source.parent.getComponent('Table').data = newData
Keywords

system dataset sort, dataset.sort

  • No labels