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.
Constructor
new SortingPlugin<T>(options?: SortingPluginOptions<T>)Options
Properties accepted by SortingPluginOptions<T>.
| Property | Description |
|---|---|
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 comparatorCompares two cell values; defaults to a type-aware comparator.
onChange: (sortModel: SortModelItem[]) => voidCalled with a copy of the sort model whenever it changes.
Instance methods
getSortModel(): SortModelItem[]Returns the current sort descriptors in priority order.
setSortModel(sortModel): voidSets the sort model. Passing an empty array clears all sorting.
clearSort(): voidRemoves all sort descriptors and restores the original row order.
setTristate(tristate): voidUpdates whether header clicks can clear the active sort.
Types and Interfaces
SortModelItemA single item in the sorting plugin's sort model.
interface SortModelItem {
/** Column identifier being sorted. */
columnId: string;
/** Sort direction. */
direction: SortDirection;
}