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.
Installation
Section titled “Installation”import { MultiSortPlugin } from '@toolbox-web/grid/plugins/multi-sort';Keyboard Shortcuts
Section titled “Keyboard Shortcuts”| Shortcut | Action |
|---|---|
Click header | Sort by column (clears other sorts) |
Shift + Click | Add column to multi-sort stack |
Ctrl + Click | Toggle sort direction |
Events
Section titled “Events”| Event | Detail | Description |
|---|---|---|
sort-change | { sortModel: SortModel[] } | Fired when sort changes |
| Option | Type | Description |
|---|---|---|
maxSortColumns? | number | Maximum number of columns that can be sorted simultaneously. Once the limit is reached, adding a new sort column replaces the oldest one. |
showSortIndex? | boolean | Whether 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. |
Examples
Section titled “Examples”Basic Multi-Column Sorting
Section titled “Basic Multi-Column Sorting”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);});Initial Sort Configuration
Section titled “Initial Sort Configuration”new MultiSortPlugin({ initialSort: [ { field: 'department', direction: 'asc' }, { field: 'salary', direction: 'desc' }, ],})See Also
Section titled “See Also”MultiSortConfigfor all configuration optionsSortModelfor the sort model structure
Extends BaseGridPlugin
Inherited methods like
attach(),detach(),afterRender(), etc. are documented in the base class.
Methods
Section titled “Methods”getSortModel()
Section titled “getSortModel()”Get the current sort model.
getSortModel(): SortModel[]Returns
Section titled “Returns”SortModel[] - Copy of the current sort model
setSortModel()
Section titled “setSortModel()”Set the sort model programmatically.
setSortModel(model: SortModel[]): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
model | SortModel[] | New sort model to apply |
clearSort()
Section titled “clearSort()”Clear all sorting.
clearSort(): voidgetSortIndex()
Section titled “getSortIndex()”Get the sort index (1-based) for a specific field.
getSortIndex(field: string): number | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
field | string | Field to check |
Returns
Section titled “Returns”number | undefined - 1-based index or undefined if not sorted
getSortDirection()
Section titled “getSortDirection()”Get the sort direction for a specific field.
getSortDirection(field: string): "desc" | "asc" | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
field | string | Field to check |
Returns
Section titled “Returns”"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