system.dataset.sort
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.
Syntax
system.dataset. sort( dataset, keyColumn [, ascending] )
-
Parameters
Dataset dataset - The dataset to sort.
int keyColumn - The index or column name of the column to sort on.
boolean ascending - True for ascending order, False for descending order. If omitted, ascending order will be used. [optional]
-
Returns
Dataset - A new sorted dataset.
-
Scope
All
Code Examples
Code Snippet
#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
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.
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