sort

Sorts the cards of a stack into a new order.

# Metadata

Platforms: desktop, server, mobile OS: mac, windows, linux, ios, android Introduced: 1.0 Security:

# Syntax

sort [marked] cards [of stack] [direction] [sortType] by sortKey

# Params

- stack : A reference to any open stack. If you don't specify a stack, the cards of the current stack are sorted. - direction : If you don't specify a <direction>, the sort is `ascending`. - sortType : If you don't specify a <sortType>, the <sortType> is `text`. - sortKey : An expression that evaluates to a value for each card in the stack. Any object references within the sortKey are treated as pertaining to each card being evaluated, so for example, a reference to a field is evaluated according to that field's contents on each card.

# Examples

sort cards by field "name"

sort cards of this stack by random(the number of cards)

sort marked cards of stack "project1" numeric by the number of buttons

sort cards numeric by the short ID of this card

sort cards of stack "Manson" descending dateTime by item 1 of field "Date"

# Description

Use the sort command to shuffle the cards in a stack into a new order, or to shuffle a subset of the cards in a stack.

The sort command is a stable sort. This means that if the sortKey for two cards is the same, sorting does not change their order, so you can do two successive sorts to create subcategories within the major sort categories. For example, to sort the cards of a stack by ZIP code and sort within each ZIP code by last names, use these two statements:

sort cards by field "Last Name" sort cards numeric by field "ZIP code"

The 'text' and 'international' forms are affected by the caseSensitive and formSensitive properties.

# Tags

# See

- **command:** find, sort container, filter - **keyword:** dateTime, numeric, text - **property:** mark