sortable.svelte.ts

Declarations
#

4 declarations

view source

sort_by_numeric
#

sortable.svelte.ts view source

<T extends Cell<any>>(key: string, label: string, field: keyof T, direction?: "asc" | "desc"): Sorter<T>

Create a numeric sorter with optional direction. Falls back to cell's cid for equal values.

key

type string

label

type string

field

type keyof T

direction

type "asc" | "desc"
default 'asc'

returns

Sorter<T>

sort_by_text
#

sortable.svelte.ts view source

<T extends Cell<any>>(key: string, label: string, field: keyof T, direction?: "asc" | "desc"): Sorter<T>

Create a text sorter with optional direction. Falls back to cell's cid for equal values.

key

type string

label

type string

field

type keyof T

direction

type "asc" | "desc"
default 'asc'

returns

Sorter<T>

Sortable
#

sortable.svelte.ts view source

Manages the sortable state for a collection of items with reactive data sources.

generics

T

items

type Array<T>

readonly

sorters

type Array<Sorter<T>>

readonly

default_key

type string | undefined

readonly

active_key

Current active sort key

type string

active_sorter

The currently active sorter.

type Sorter<T> | undefined

readonly

active_sort_fn

The sort function from the active sorter.

type ((a: T, b: T) => number) | undefined

readonly

sorted_items

Sorted items based on the current active sorter.

type Array<T>

readonly

constructor

Create a new Sortable instance with reactive sources.

type new <T>(items_getter: Thunk<T[]>, sorters_getter: Thunk<Sorter<T>[]>, key_getter_default?: Thunk<string | undefined> | undefined): Sortable<T>

items_getter

Function that returns the current items array

type Thunk<T[]>
sorters_getter

Function that returns the current sorters

type Thunk<Sorter<T>[]>
key_getter_default?

Optional function that returns the current default sort key

type Thunk<string | undefined> | undefined
optional

update_active_key

Updates the active key based on sorters and default key. Called automatically on initialization and when sorters change.

type (): void

returns void

Sorter
#

Imported by
#