API / Plugins / Base / Sorting

SortingPlugin

The SortingPlugin from @omnigrid/sorting-plugin adds column-header sorting to the grid. Clicking a column header toggles asc / desc / unsorted. Hold Ctrl while clicking to sort by multiple columns. A custom comparator can be supplied to control how values are compared.

Live demo|NPM

Constructor

new SortingPlugin<T>(options?: SortingPluginOptions<T>)

Options

Properties accepted by SortingPluginOptions<T>.

PropertyDescription

mode

"client" | "server"default: "client"

Runs sorting locally or leaves row ordering to the data source.

tristate

booleandefault: true

Enables the `asc -> desc -> none` header-click cycle.

Callbacks

compare: (left: unknown, right: unknown, column: ColumnLeafDef<T>) => numberdefault: built-in type-aware comparator

Compares two cell values; defaults to a type-aware comparator.

onChange: (sortModel: SortModelItem[]) => void

Called with a copy of the sort model whenever it changes.

Instance methods

getSortModel(): SortModelItem[]

Returns the current sort descriptors in priority order.

setSortModel(sortModel): void

Sets the sort model. Passing an empty array clears all sorting.

clearSort(): void

Removes all sort descriptors and restores the original row order.

setTristate(tristate): void

Updates whether header clicks can clear the active sort.

Types and Interfaces

SortModelItem

A single item in the sorting plugin's sort model.

interface SortModelItem {
    /** Column identifier being sorted. */
    columnId: string;
    /** Sort direction. */
    direction: SortDirection;
}