Skip to main content

Datatable-Sorting

Command Description

Sort the specified column of a datatable

Command Prototype

dtTable = Datatable.SortDataTable(dataTable,columns,bAscSort)

Parameter Description

ParameterRequiredTypeDefaultDescription
dataTableTrueexpressionobjDatatableThe data table to be filtered
columnsTruestring""Data columns to be sorted, can be filled with strings or numbers. Sort the column named "string" if filled with strings; sort multiple columns in the array if filled with an array
bAscSortTruebooleanTrueWhether to sort in ascending order, if choose no, sort in descending order

return

dtTable,The variable used to save the output of the command.

Demo

aryData = [["a", 1], ["b", 2], ["c", 3], ["d", 1]] 
aryColumns = ["letter", "number"]
objDatatable = Datatable.BuildDataTable(aryData,aryColumns)
dtTable = Datatable.SortDataTable(objDatatable,"number",false)

TracePrint(dtTable)
/*
letter number
2 c 3
1 b 2
0 a 1
3 d 1
*/