import { BasePlugin } from '../base'; import { IndexesSequence, PhysicalIndexToValueMap as IndexToValueMap } from '../../translations'; import { ColumnStatesManager } from './columnStatesManager'; export interface ColumnSortingConfig { column: number; sortOrder: 'asc' | 'desc' | 'none'; } export declare const PLUGIN_KEY = "columnSorting"; export declare const PLUGIN_PRIORITY = 50; export declare const APPEND_COLUMN_CONFIG_STRATEGY = "append"; export declare const REPLACE_COLUMN_CONFIG_STRATEGY = "replace"; export interface SortConfig { column: number; sortOrder: string; } /** * @plugin ColumnSorting * @class ColumnSorting * * @description * This plugin sorts the view by columns (but does not sort the data source!). To enable the plugin, set the * {@link Options#columnSorting} property to the correct value (see the examples below). * * @example * ```js * // as boolean * columnSorting: true * * // as an object with initial sort config (sort ascending for column at index 1) * columnSorting: { * initialConfig: { * column: 1, * sortOrder: 'asc' * } * } * * // as an object which define specific sorting options for all columns * columnSorting: { * sortEmptyCells: true, // true = the table sorts empty cells, false = the table moves all empty cells to the end of the table (by default) * indicator: true, // true = shows indicator for all columns (by default), false = don't show indicator for columns * headerAction: true, // true = allow to click on the headers to sort (by default), false = turn off possibility to click on the headers to sort * compareFunctionFactory: function(sortOrder, columnMeta) { * return function(value, nextValue) { * // Some value comparisons which will return -1, 0 or 1... * } * } * } * * // as an object passed to the `column` property, allows specifying a custom options for the desired column. * // please take a look at documentation of `column` property: https://handsontable.com/docs/Options.html#columns * columns: [{ * columnSorting: { * indicator: false, // disable indicator for the first column, * sortEmptyCells: true, * headerAction: false, // clicks on the first column won't sort * compareFunctionFactory: function(sortOrder, columnMeta) { * return function(value, nextValue) { * return 0; // Custom compare function for the first column (don't sort) * } * } * } * }] * ``` */ export declare class ColumnSorting extends BasePlugin { #private; /** * Returns the plugin key used to identify this plugin in Handsontable settings. */ static get PLUGIN_KEY(): string; /** * Returns the priority order used to determine the order in which plugins are initialized. */ static get PLUGIN_PRIORITY(): number; /** * Instance of column state manager. * * @private * @type {null|ColumnStatesManager} */ columnStatesManager: ColumnStatesManager | null; /** * Cached column properties from plugin like i.e. `indicator`, `headerAction`. * * @private * @type {null|PhysicalIndexToValueMap} */ columnMetaCache: IndexToValueMap | null; /** * Main settings key designed for the plugin. * * @private * @type {string} */ pluginKey: string; /** * Plugin indexes cache. * * @private * @type {null|IndexesSequence} */ indexesSequenceCache: IndexesSequence | null; /** * Checks if the plugin is enabled in the Handsontable settings. This method is executed in {@link Hooks#beforeInit} * hook and if it returns `true` then the {@link ColumnSorting#enablePlugin} method is called. * * @returns {boolean} */ isEnabled(): boolean; /** * Enables the plugin functionality for this Handsontable instance. */ enablePlugin(): void; /** * Disables the plugin functionality for this Handsontable instance. */ disablePlugin(): void; /** * Register shortcuts responsible for toggling column sorting functionality. * * @private */ registerShortcuts(): void; /** * Unregister shortcuts responsible for toggling column sorting functionality. * * @private */ unregisterShortcuts(): void; /** * Sorts the table by chosen columns and orders. * * @param {undefined|object} sortConfig Single column sort configuration. The configuration object contains `column` and `sortOrder` properties. * First of them contains visual column index, the second one contains sort order (`asc` for ascending, `desc` for descending). * * **Note**: Please keep in mind that every call of `sort` function set an entirely new sort order. Previous sort configs aren't preserved. * * @example * ```js * // sort ascending first visual column * hot.getPlugin('columnSorting').sort({ column: 0, sortOrder: 'asc' }); * ``` * * @fires Hooks#beforeColumnSort * @fires Hooks#afterColumnSort */ sort(sortConfig?: SortConfig | SortConfig[]): void; /** * Clear the sort performed on the table. */ clearSort(): void; /** * Checks if the table is sorted (any column have to be sorted). * * @returns {boolean} */ isSorted(): boolean; /** * Get sort configuration for particular column or for all sorted columns. Objects contain `column` and `sortOrder` properties. * * **Note**: Please keep in mind that returned objects expose **visual** column index under the `column` key. They are handled by the `sort` function. * * @param {number} [column] Visual column index. * @returns {undefined|object|Array} */ getSortConfig(column?: number): SortConfig | SortConfig[] | undefined; /** * @description * Warn: Useful mainly for providing server side sort implementation (see in the example below). It doesn't sort the data set. It just sets sort configuration for all sorted columns. * Note: Please keep in mind that this method doesn't re-render the table. * * @example * ```js * beforeColumnSort: function(currentSortConfig, destinationSortConfigs) { * const columnSortPlugin = this.getPlugin('columnSorting'); * * columnSortPlugin.setSortConfig(destinationSortConfigs); * * // const newData = ... // Calculated data set, ie. from an AJAX call. * * this.updateData(newData); // Update data set and re-render the table. * * return false; // The blockade for the default sort action. * } * ``` * * @param {undefined|object|Array} sortConfig Single column sort configuration or full sort configuration (for all sorted columns). * The configuration object contains `column` and `sortOrder` properties. First of them contains visual column index, the second one contains * sort order (`asc` for ascending, `desc` for descending). */ setSortConfig(sortConfig?: SortConfig | SortConfig[]): void; /** * Get normalized sort configs. * * @private * @param {object|Array} [sortConfig=[]] Single column sort configuration or full sort configuration (for all sorted columns). * The configuration object contains `column` and `sortOrder` properties. First of them contains visual column index, the second one contains * sort order (`asc` for ascending, `desc` for descending). * @returns {Array} */ getNormalizedSortConfigs(sortConfig?: SortConfig | SortConfig[]): SortConfig[]; /** * Get if sort configs are valid. * * @private * @param {Array} sortConfigs Sort configuration for all sorted columns. Objects contain `column` and `sortOrder` properties. * @returns {boolean} */ areValidSortConfigs(sortConfigs: SortConfig[]): boolean; /** * Get next sort configuration for particular column. Object contain `column` and `sortOrder` properties. * * **Note**: Please keep in mind that returned object expose **visual** column index under the `column` key. * * @private * @param {number} column Visual column index. * @returns {undefined|object} */ getColumnNextConfig(column: number): SortConfig | undefined; /** * Get sort configuration with "next order" for particular column. * * @private * @param {number} columnToChange Visual column index of column which order will be changed. * @param {string} strategyId ID of strategy. Possible values: 'append' and 'replace'. The first one * change order of particular column and change it's position in the sort queue to the last one. The second one * just change order of particular column. * * **Note**: Please keep in mind that returned objects expose **visual** column index under the `column` key. * * @returns {Array} */ getNextSortConfig(columnToChange: number, strategyId?: string): ({ column: number; } | undefined)[]; /** * Get plugin's column config for the specified column index. * * @private * @param {object} columnConfig Configuration inside `columns` property for the specified column index. * @returns {object} */ getPluginColumnConfig(columnConfig: Record): unknown; /** * Get plugin settings related properties, properly merged from cascade settings. * * @private * @param {number} column Visual column index. * @returns {object} */ getMergedPluginSettings(column: number): Record; /** * Get copy of settings for first cell in the column. * * @private * @param {number} column Visual column index. * @returns {object} */ getFirstCellSettings(column: number): Record; /** * Get number of rows which should be sorted. * * @private * @param {number} numberOfRows Total number of displayed rows. * @returns {number} */ getNumberOfRowsToSort(numberOfRows: number): number; /** * Performs the sorting using a stable sort function basing on internal state of sorting. * * @param {Array} sortConfigs Sort configuration for all sorted columns. Objects contain `column` and `sortOrder` properties. * @private */ sortByPresetSortStates(sortConfigs: SortConfig[]): void; /** * Sort the table by provided configuration. * * @private * @param {object} allSortSettings All sort config settings. Object may contain `initialConfig`, `indicator`, * `sortEmptyCells`, `headerAction` and `compareFunctionFactory` properties. */ sortBySettings(allSortSettings: unknown): void; /** * Update header classes. * * @private * @param {HTMLElement} headerSpanElement Header span element. * @param {...*} args Extra arguments for helpers. */ updateHeaderClasses(headerSpanElement: HTMLElement, columnStatesManager?: ColumnStatesManager, column?: number, showSortIndicator?: boolean, headerActionEnabled?: boolean): void; /** * Overwriting base plugin's `onUpdateSettings` method. Please keep in mind that `onAfterUpdateSettings` isn't called * for `updateSettings` in specific situations. * * @private * @param {object} newSettings New settings object. */ onUpdateSettings(newSettings: Record): void; /** * Indicates if clickable header was clicked. * * @private * @param {MouseEvent} event The `mousedown` event. * @param {number} column Visual column index. * @returns {boolean} */ wasClickableHeaderClicked(event: Event, column: number): boolean; /** * Callback for the `onAfterOnCellMouseDown` hook. * * @private * @param {Event} event Event which are provided by hook. * @param {CellCoords} coords Visual coords of the selected cell. */ onAfterOnCellMouseDown(event: Event, coords: { row: number; col: number; }): void; /** * Destroys the plugin instance. */ destroy(): void; }