# `LiveFilter.Sort`
[🔗](https://github.com/agoodway/livefilter/blob/v0.2.0/lib/live_filter/sort.ex#L1)

Sort state — a list of `LiveFilter.Sort.Entry` ordered by priority.

An orthogonal, URL-shareable concern (like `LiveFilter.Pagination`). The list
is multi-column ready even though the bundled UI sets a single active sort.
`entries: []` means "no explicit sort" — the consumer's default ordering applies.

## Example

    {sort, remaining} = LiveFilter.sort_from_params(params, sortable_fields)
    LiveFilter.Sort.to_params(sort)            # => %{"order" => "clicks.desc"}
    LiveFilter.Sort.direction_for(sort, :clicks) # => :desc

# `t`

```elixir
@type t() :: %LiveFilter.Sort{entries: [LiveFilter.Sort.Entry.t()]}
```

# `clear`

```elixir
@spec clear(t()) :: t()
```

Clears all sort entries.

# `clear`

```elixir
@spec clear(t(), atom()) :: t()
```

Removes the entry for `field` (no-op if absent).

# `direction_for`

```elixir
@spec direction_for(t(), atom()) :: LiveFilter.Sort.Entry.direction() | nil
```

Direction of `field` in the current sort, or `nil` if it is not sorted.

# `put`

```elixir
@spec put(t(), atom(), LiveFilter.Sort.Entry.direction(), keyword()) :: t()
```

Sets a single explicit sort entry, replacing any current sort.

# `to_params`

```elixir
@spec to_params(t()) :: map()
```

Serializes to a PostgREST-compatible param map. Returns `%{}` (no `order` key)
when the sort is empty, keeping default-state URLs clean.

# `toggle`

```elixir
@spec toggle(t(), atom()) :: t()
```

Tri-state single-sort toggle for a header click.

Cycle: `none -> default_direction -> opposite -> none`. Replaces any other
active sort (single-sort UI).

## Options
  * `:default_direction` - first-click direction (default `:asc`)
  * `:nulls` - nulls placement to carry onto the new entry (default `nil`)

# `toggle`

```elixir
@spec toggle(t(), atom(), [LiveFilter.SortField.t()] | keyword()) :: t()
```

Tri-state toggle that reads the field's `default_direction`/`nulls` from a
`LiveFilter.SortField` list. A field not present in the list is treated as
not sortable and the sort is returned unchanged (no-op).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
