> ## Documentation Index
> Fetch the complete documentation index at: https://learn.nextedy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure Column Sorting

> Set up default sort order and enable interactive column sorting in the Nextedy RISKSHEET grid.

export const LastReviewed = ({date}) => {
  if (!date) return null;
  const formatted = new Date(`${date}T00:00:00Z`).toLocaleDateString("en-US", {
    year: "numeric",
    month: "long",
    day: "numeric",
    timeZone: "UTC"
  });
  return <p className="mt-10 text-sm text-gray-400 dark:text-zinc-500 not-prose">
      Last reviewed on {formatted}
    </p>;
};

## Configure Default Sort Order

Add a top-level `sortBy` array to the sheet configuration. The array contains column ID strings in priority sequence:

```yaml theme={null}
sortBy:
  - severity
  - rpn
columns:
  - id: severity
    header: Severity
    bindings: severity
    type: enum
  - id: rpn
    header: RPN
    bindings: rpn
    type: int
    formula: commonRpn
```

The grid sorts by the first column ID on load, then uses subsequent column IDs as tiebreakers for equal values.

### Sort Descending

Prefix a column ID with `~` (tilde) to sort that column in descending order:

```yaml theme={null}
sortBy:
  - ~rpn
  - priority
```

This sorts by RPN descending (highest risk first), then by priority ascending.

## Sort by Outline Number

To maintain the same item order as in the Polarion LiveDoc, sort by outline number. Because outline numbers sort lexicographically by default (`1.10` before `1.2`), you need a server-rendered column that zero-pads each segment.

**Step 1** -- Add a hidden server-rendered column that formats the outline number:

```yaml theme={null}
columns:
  - id: outlineSort
    header: Outline
    bindings: outlineNumber
    serverRender: "#set($on=$item.fields().get('outlineNumber').get())#if($on)#foreach($s in $on.split('\\.'))$String.format('%05d',$Integer.parseInt($s))#if($foreach.hasNext).#end#end#end"
    width: 0
    visible: false
```

**Step 2** -- Set the column as the default sort:

```yaml theme={null}
sortBy:
  - outlineSort
```

<Tip title="Why zero-padding is needed">
  Without zero-padding, outline numbers sort lexicographically: `1.10` comes before `1.2`. The Velocity snippet pads each segment to five digits (`00001.00002`), ensuring `1.2` correctly sorts before `1.10`.
</Tip>

## Interactive Sorting

Users can sort columns at runtime by clicking column headers:

* **Single click** on a column header sorts ascending
* **Click again** on the same header to switch to descending
* **Ctrl+Click** (Windows/Linux) or **Cmd+Click** (macOS) adds the column as a secondary sort criterion without clearing the existing sort

<Warning title="Merged column headers do not support sorting">
  When column headers span multiple columns (using `columnSpan`), clicking the merged header does not trigger sorting. Click individual sub-column headers instead.
</Warning>

## Sorting Behavior by Column Type

Risksheet applies specialized sorting logic automatically based on column type:

| Column Type            | Sort Behavior                                                       |
| ---------------------- | ------------------------------------------------------------------- |
| `string`, `enum`       | Alphabetical                                                        |
| `int`, `float`         | Numeric                                                             |
| `itemLink`, `taskLink` | Alphanumeric work item ID sorting (`PROJECT-2` before `PROJECT-10`) |
| `multiItemLink`        | Concatenates all linked item labels, sorts alphabetically           |
| Outline number binding | Hierarchical sort (`1.2` before `1.10`)                             |
| Nested properties      | Sorts by the linked item's property value, not the link itself      |

<Info title="Verify in application">
  Sort behavior for custom `serverRender` columns depends on the rendered output format. Test sorting after adding server-rendered columns.
</Info>

## Comparison Mode Constraints

When comparing to a baseline, Risksheet enforces specific sorting rules:

* The grid automatically sorts by **Item ID** then **Revision number** -- this cannot be overridden
* **Task and downstream columns** cannot be sorted in comparison mode
* Sorting operates on baseline snapshot values rather than current values (except for system identity fields like `systemItemId` and `systemItemRevision`)

<Warning title="Sort criteria reset in comparison mode">
  Entering comparison mode removes any task column sort criteria and applies mandatory Item ID + Revision sorting. Your previous sort order is not preserved when you enter or exit comparison mode.
</Warning>

## Automatic Behaviors

Risksheet handles several sorting details automatically:

* **Pending edits are saved** before sorting occurs -- you will not lose unsaved changes when clicking a header
* **Client-side execution** -- sorting, filtering, and pagination happen in the browser without server round-trips, providing immediate visual feedback
* **Unsaved items** (prefixed with `*`) sort with the asterisk intact, keeping newly created items visible

## URL Parameter for Sorting

You can also drive sorting via the `sort` URL parameter, which uses the same syntax as `sortBy` (comma-separated column IDs, with `~` prefix for descending):

```
?sort=~rpn,priority
```

This is useful for sharing deep links that open Risksheet pre-sorted to a specific order.

## Verify

After configuring `sortBy`, reload the Risksheet page. The grid should display rows in the specified order on initial load. Click column headers to confirm interactive sorting works and verify that Ctrl/Cmd+Click enables multi-column sorting.

## See Also

* [Add a Basic Column](/risksheet/guides/columns/add-basic-column) -- column property reference including `id` and `bindings`
* [Display Sub-Columns](/risksheet/guides/columns/sub-columns) -- nested column configuration
* [Control Column Visibility](/risksheet/guides/columns/column-visibility) -- show or hide columns
* [Create Saved Views](/risksheet/guides/customization/saved-views) -- save different column and sort arrangements

<LastReviewed date="2026-06-24" />
