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';
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
OptionTypeDescription
maxSortColumns?numberMaximum number of columns that can be sorted simultaneously. Once the limit is reached, adding a new sort column replaces the oldest one.
showSortIndex?booleanWhether to show numbered badges (1, 2, 3…) on sorted column headers to indicate sort precedence. Disable for a cleaner look when precedence is not important to the user.
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