---
url: "https://vueda.dev/v3/reference/api/js/utils/sortedFields.md"
title: "utils/sortedFields"
---

# utils/sortedFields

## Overview

Pure helpers for the ViewList sort order representation: an array of field
names where a leading `-` marks descending order (e.g. `["-updated", "mrr"]` is Updated
descending, then MRR ascending). This is the single home for the `-` prefix convention and
the add / remove / toggle edit operations, shared by the sort surfaces (column-header
sorting in `ObjectsGrid`, the `SortControl` add menu, and the `SortGroup` chips) so they
cannot drift.

A given base field appears at most once in a sort order, so edits are keyed by base field
name rather than by array position. Every function is non-mutating and returns a fresh array.

## Methods

- [addSortField](/v3/reference/api/js/utils/sortedFields/functions/addSortField.md) - Append `base` to the sort order.
- [formatSortField](/v3/reference/api/js/utils/sortedFields/functions/formatSortField.md) - Build a sort entry from a base field name and direction.
- [formatSortQuery](/v3/reference/api/js/utils/sortedFields/functions/formatSortQuery.md) - Serialize a sort order for the browser query string.
- [indexOfSortField](/v3/reference/api/js/utils/sortedFields/functions/indexOfSortField.md) - Position of `base` within the sort order, regardless of direction; `-1` when absent.
- [parseSortField](/v3/reference/api/js/utils/sortedFields/functions/parseSortField.md) - Split a sort entry into its base field name and direction.
- [parseSortQuery](/v3/reference/api/js/utils/sortedFields/functions/parseSortQuery.md) - Parse the browser query representation of a sort order.
- [removeSortField](/v3/reference/api/js/utils/sortedFields/functions/removeSortField.md) - Remove `base` from the sort order (matched by base, ignoring direction).
- [sanitizeSortFields](/v3/reference/api/js/utils/sortedFields/functions/sanitizeSortFields.md) - Keep only valid sortable fields, preserving the first occurrence and direction.
- [sortFieldBases](/v3/reference/api/js/utils/sortedFields/functions/sortFieldBases.md) - The base field name of every entry, direction stripped.
- [toggleSortField](/v3/reference/api/js/utils/sortedFields/functions/toggleSortField.md) - Flip the direction of `base` in place within the sort order.

## Types

### [ParsedSortField](/v3/reference/api/js/utils/sortedFields/types/ParsedSortField.md)

## Source

`client/lib/utils/sortedFields.js:1`
