--- title: "system.dataset.sort" description: "Sorts a dataset and returns the sorted dataset." --- # system.dataset.sort > Sorts a dataset and returns the sorted dataset. 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](projects\project-properties\project-properties.md#client---permissions) restrictions. ## Syntax `system.dataset.sort(dataset, keyColumn [, ascending])` ### Parameters Type | Parameter | Description ------- | ------- | ------ 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 ] PyObject | `value` | The new value for the specified row/column. ### Returns **Dataset** - A new sorted dataset. ### Scope All ## Code Examples ```python title="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 ``` ```python title="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 ```