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
Summary
Functions
Clears all sort entries.
Removes the entry for field (no-op if absent).
Direction of field in the current sort, or nil if it is not sorted.
Sets a single explicit sort entry, replacing any current sort.
Serializes to a PostgREST-compatible param map. Returns %{} (no order key)
when the sort is empty, keeping default-state URLs clean.
Tri-state single-sort toggle for a header click.
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).
Types
@type t() :: %LiveFilter.Sort{entries: [LiveFilter.Sort.Entry.t()]}
Functions
Clears all sort entries.
Removes the entry for field (no-op if absent).
@spec direction_for(t(), atom()) :: LiveFilter.Sort.Entry.direction() | nil
Direction of field in the current sort, or nil if it is not sorted.
@spec put(t(), atom(), LiveFilter.Sort.Entry.direction(), keyword()) :: t()
Sets a single explicit sort entry, replacing any current sort.
Serializes to a PostgREST-compatible param map. Returns %{} (no order key)
when the sort is empty, keeping default-state URLs clean.
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 (defaultnil)
@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).