Skip to content

MultiSortPlugin

Multi-Sort Plugin for tbw-grid

Enables sorting by multiple columns at once—hold Shift and click additional column headers to build up a sort stack. Priority badges show the sort order, so users always know which column takes precedence.

import { MultiSortPlugin } from '@toolbox-web/grid/plugins/multi-sort';
OptionTypeDefaultDescription
maxSortColumnsnumber3Maximum columns to sort by
showSortIndexbooleantrueShow sort priority badges
initialSortSortModel[]-Pre-configured sort order on load
ShortcutAction
Click headerSort by column (clears other sorts)
Shift + ClickAdd column to multi-sort stack
Ctrl + ClickToggle sort direction
EventDetailDescription
sort-change{ sortModel: SortModel[] }Fired when sort changes
MethodSignatureDescription
setSort(sortModel: SortModel[]) => voidSet sort programmatically
getSortModel() => SortModel[]Get current sort model
clearSort() => voidClear all sorting
addSort(field, direction) => voidAdd a column to sort
removeSort(field) => voidRemove a column from sort
import { queryGrid } from '@toolbox-web/grid';
import { MultiSortPlugin } from '@toolbox-web/grid/plugins/multi-sort';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'name', header: 'Name', sortable: true },
{ field: 'department', header: 'Department', sortable: true },
{ field: 'salary', header: 'Salary', type: 'number', sortable: true },
],
plugins: [new MultiSortPlugin({ maxSortColumns: 3, showSortIndex: true })],
};
grid.on('sort-change', ({ sortModel }) => {
console.log('Active sorts:', sortModel);
});
new MultiSortPlugin({
initialSort: [
{ field: 'department', direction: 'asc' },
{ field: 'salary', direction: 'desc' },
],
})

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

Get the current sort model.

getSortModel(): SortModel[]

SortModel[] - Copy of the current sort model


Set the sort model programmatically.

setSortModel(model: SortModel[]): void
NameTypeDescription
modelSortModel[]New sort model to apply

Clear all sorting.

clearSort(): void

Get the sort index (1-based) for a specific field.

getSortIndex(field: string): number | undefined
NameTypeDescription
fieldstringField to check

number | undefined - 1-based index or undefined if not sorted


Get the sort direction for a specific field.

getSortDirection(field: string): "desc" | "asc" | undefined
NameTypeDescription
fieldstringField to check

"desc" | "asc" | undefined - Sort direction or undefined if not sorted


AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt