sort-datatable

Description

sort-datatable adaptor sorts specified columns of a datatable in either ascending (asc) or descending (desc) order.

In ascending mode, numbers come first and then text (1,2,cow), in descending mode text comes first (cow,2,1).

Inputs

data Type: datatable Required: Yes The datatable to be sorted.

column names Type: dictionary Required: Yes A dictionary of column names with sort direction, where the keys are the column names, and the values should be either asc (for ascending order) or desc (for descending order).

Outputs

data Type: datatable A datatable with the sorted rows.

Examples

Example 1: Default behaviour.

Inputs:

data:

idcodename

1

GB

United Kingdom

2

TR

Turkey

3

US

United States

4

IND

India

5

IND

India

6

us

United States

column names:

KEYVALUE

code

desc

Outputs:

data:

idcodename

6

us

United States

3

US

United States

2

TR

Turkey

4

IND

India

5

IND

India

1

GB

United Kingdom

-> Sorted datatable based on code column in descending order.

Example 2: Sorting by multiple columns.

Inputs:

data:

idCountryState/Province

1

United States

West Virginia

2

United States

Minnesota

3

Canada

Ontario

4

Canada

Quebec

5

Canada

British Columbia

6

United States

California

column names:

KEYVALUE

Country

asc

State/Province

asc

Outputs:

data:

idCountryState/Province

5

Canada

British Columbia

3

Canada

Ontario

4

Canada

Quebec

6

United States

California

2

United States

Minnesota

1

United States

West Virginia

-> Sorted datatable based on first the Country and then the State/Province column in ascending order.

Use case

  • Place high-impact rows at the top of a data set (e.g. to be easiest to find in Microreact data table).

  • Organize data for sharing in a report.

Last updated