Skip to content

Table manipulation

Giorgio Garofalo edited this page Mar 31, 2025 · 2 revisions

Sort rows

The .tablesort function sorts a table based on the values of a specific column.

Parameter Description Accepts
column Index of the column, starting from 1. 1 to number of columns.
order Sorting order. ascending (default), descending
.tablesort {2} order:{descending}
    | Name | Age | City |
    |------|-----|------|
    | John | 25  | NY   |
    | Lisa | 32  | LA   |
    | Mike | 19  | CHI  |

Result:

| Name | Age | City |
|------|-----|------|
| Lisa | 32  | LA   |
| John | 25  | NY   |
| Mike | 19  | CHI  |

Notes:

  • Uses column values as sorting keys.
  • Works with nested/generated tables (e.g., from csv).

 

Filter rows

The .tablefilter function keeps or removes rows based on the values of a specific column.

Parameter Description Accepts
column Index of the column, starting from 1. 1 to number of columns.
filter Lambda that returns whether each row should be kept, with the value of its cell in the corresponding column as input. DynamicBoolean lambda
.tablefilter {2} {@lambda x: .x::isgreater {20}}
    | Name | Age | City |
    |------|-----|------|
    | John | 25  | NY   |
    | Lisa | 32  | LA   |
    | Mike | 19  | CHI  |

Result:

| Name | Age | City |
|------|-----|------|
| John | 25  | NY   |
| Lisa | 32  | LA   |

 

Compute/aggregate columns

The .tablecompute function computes the cells in a column and appends the result to a new row.

Parameter Description Accepts
column Index of the column, starting from 1. 1 to number of columns.
compute Lambda that returns the computed value, with the collection of the cells in the column as input. IterableDynamic lambda

See Iterable to learn more about available operations on collections.

Example:

.tablecompute {2} {@lambda x: .x::average::round}
    | Name | Age | City |
    |------|-----|------|
    | John | 25  | NY   |
    | Lisa | 32  | LA   |
    | Mike | 19  | CHI  |

Result:

| Name | Age | City |
|------|-----|------|
| John | 25  | NY   |
| Lisa | 32  | LA   |
| Mike | 19  | CHI  |
|      | 25  |      |

 

Composition

Multiple table operations can be chained. The order of the operations goes from inner to outer:

.tablecompute {2} {@lambda x: .x::average::round}
    .tablesort {2}
        | Name | Age | City |
        |------|-----|------|
        | John | 25  | NY   |
        | Lisa | 32  | LA   |
        | Mike | 19  | CHI  |

Result:

| Name | Age | City |
|------|-----|------|
| Mike | 19  | CHI  |
| John | 25  | NY   |
| Lisa | 32  | LA   |
|      | 25  |      |

 

Versatility

Table operations can affect not only plain Markdown tables, but also any kind of table including those loaded from CSV.

.tablesort {2} order:{descending}
    .csv {people.csv}
Clone this wiki locally