@revolist/revogrid 4.9.40 → 4.9.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/revo-grid.cjs.entry.js +2 -2
- package/dist/cjs/revo-grid.cjs.entry.js.map +1 -1
- package/dist/collection/plugins/sorting/sorting.plugin.js +2 -2
- package/dist/collection/plugins/sorting/sorting.plugin.js.map +1 -1
- package/dist/esm/revo-grid.entry.js +2 -2
- package/dist/esm/revo-grid.entry.js.map +1 -1
- package/dist/revo-grid/revo-grid.entry.js +1 -1
- package/dist/revo-grid/revo-grid.entry.js.map +1 -1
- package/hydrate/index.js +2 -2
- package/hydrate/index.mjs +2 -2
- package/package.json +1 -1
- package/standalone/revo-grid.js +2 -2
- package/standalone/revo-grid.js.map +1 -1
|
@@ -178,8 +178,8 @@ export default class SortingPlugin extends BasePlugin {
|
|
|
178
178
|
}
|
|
179
179
|
defaultCellCompare(prop, a, b) {
|
|
180
180
|
var _a, _b;
|
|
181
|
-
const av = (_a = a[prop]) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase();
|
|
182
|
-
const bv = (_b = b[prop]) === null || _b === void 0 ? void 0 : _b.toString().toLowerCase();
|
|
181
|
+
const av = (_a = a === null || a === void 0 ? void 0 : a[prop]) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase();
|
|
182
|
+
const bv = (_b = b === null || b === void 0 ? void 0 : b[prop]) === null || _b === void 0 ? void 0 : _b.toString().toLowerCase();
|
|
183
183
|
return av == bv ? 0 : av > bv ? 1 : -1;
|
|
184
184
|
}
|
|
185
185
|
descCellCompare(cmp) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sorting.plugin.js","sourceRoot":"","sources":["../../../src/plugins/sorting/sorting.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,UAAU,E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AI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9B,CAAC,CAAC;IACJ,CAAC;IAED,gBAAgB,CACd,OAAiB,EACjB,MAAkB,EAClB,cAAoC,EAAE;QAEtC,0CAA0C;QAC1C,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7C,mBAAmB;YACnB,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QACD,EAAE;QACF;;;WAGG;QACH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC3B,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;gBACtD,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBACxB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAExB;;;mBAGG;gBACH,MAAM,MAAM,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAG,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;gBACzC,IAAI,MAAM,EAAE,CAAC;oBACX,OAAO,MAAM,CAAC;gBAChB,CAAC;YACH,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAC,YAAmB;QAC9B,QAAQ,YAAY,EAAE,CAAC;YACrB,KAAK,SAAS;gBACZ,OAAO,KAAK,CAAC;YACf,KAAK,KAAK;gBACR,OAAO,MAAM,CAAC;YAChB,KAAK,MAAM;gBACT,OAAO,SAAS,CAAC;QACrB,CAAC;IACH,CAAC;CACF","sourcesContent":["import size from 'lodash/size';\nimport debounce from 'lodash/debounce';\n\nimport { BasePlugin } from '../base.plugin';\nimport {\n ColumnProp,\n Order,\n CellCompareFunc,\n ColumnRegular,\n InitialHeaderClick,\n DataType,\n DimensionRows,\n PluginProviders,\n} from '@type';\nimport { getColumnByProp } from '../../utils/column.utils';\nimport { rowTypes } from '@store';\n\nexport type SortingOrder = Record<ColumnProp, Order>;\ntype SortingOrderFunction = Record<ColumnProp, CellCompareFunc | undefined>;\ntype ColumnSetEvent = {\n order: SortingOrder;\n};\n\n/**\n * Lifecycle\n * 1. @event `beforesorting` - Triggered when sorting just starts. Nothing has happened yet. This can be triggered from a column or from the source. If the type is from rows, the column will be undefined.\n * 2. @method `updateColumnSorting` - Updates the column sorting icon on the grid and the column itself, but the data remains untouched.\n * 3. @event `beforesortingapply` - Triggered before the sorting data is applied to the data source. You can prevent this event, and the data will not be sorted. This event is only called from a column sorting click.\n * 4. @event `aftersortingapply` - Triggered after sorting has been applied and completed. This event occurs for both row and column sorting.\n *\n * Note: If you prevent an event, it will not proceed to the subsequent steps.\n */\n\nexport default class SortingPlugin extends BasePlugin {\n // sorting order per column\n sorting?: SortingOrder;\n\n // sorting function per column, multiple columns sorting supported\n sortingFunc?: SortingOrderFunction;\n sortingPromise: (() => void) | null = null;\n postponeSort = debounce(\n (order?: SortingOrder, comparison?: SortingOrderFunction) =>\n this.runSorting(order, comparison),\n 50,\n );\n\n runSorting(\n order?: SortingOrder,\n comparison?: SortingOrderFunction,\n ) {\n this.sort(order, comparison);\n this.sortingPromise?.();\n this.sortingPromise = null;\n }\n\n constructor(\n public revogrid: HTMLRevoGridElement,\n providers: PluginProviders,\n ) {\n super(revogrid, providers);\n\n const beforeanysource = ({\n detail: { type },\n }: CustomEvent<{\n type: DimensionRows;\n source: any[];\n }>) => {\n // if sorting was provided - sort data\n if (!!this.sorting && this.sortingFunc) {\n const beforeEvent = this.emit('beforesorting', { type });\n if (beforeEvent.defaultPrevented) {\n return;\n }\n this.startSorting(this.sorting, this.sortingFunc);\n }\n };\n const aftercolumnsset = ({\n detail: { order },\n }: CustomEvent<ColumnSetEvent>) => {\n const columns = this.providers.column.getColumns();\n const sortingFunc: SortingOrderFunction = {};\n\n for (let prop in order) {\n const cmp = this.getComparer(\n getColumnByProp(columns, prop),\n order[prop],\n );\n sortingFunc[prop] = cmp;\n }\n this.runSorting(order, sortingFunc);\n };\n const headerclick = (e: CustomEvent<InitialHeaderClick>) => {\n if (e.defaultPrevented) {\n return;\n }\n\n if (!e.detail.column.sortable) {\n return;\n }\n\n this.headerclick(\n e.detail.column,\n e.detail.index,\n e.detail?.originalEvent?.shiftKey,\n );\n };\n\n this.addEventListener('beforeanysource', beforeanysource);\n this.addEventListener('aftercolumnsset', aftercolumnsset);\n this.addEventListener('beforeheaderclick', headerclick);\n }\n\n startSorting(order?: SortingOrder, sortingFunc?: SortingOrderFunction) {\n if (!this.sortingPromise) {\n this.revogrid.jobsBeforeRender.push(\n new Promise<void>(resolve => {\n this.sortingPromise = resolve;\n }),\n );\n }\n this.postponeSort(order, sortingFunc);\n }\n\n getComparer(column: ColumnRegular | undefined, order: Order): CellCompareFunc | undefined {\n const cellCmp: CellCompareFunc =\n column?.cellCompare?.bind({ order }) || this.defaultCellCompare;\n if (order == 'asc') {\n return cellCmp;\n }\n if (order == 'desc') {\n return this.descCellCompare(cellCmp);\n }\n return undefined;\n }\n\n /**\n * Apply sorting to data on header click\n * If additive - add to existing sorting, multiple columns can be sorted\n */\n headerclick(column: ColumnRegular, index: number, additive: boolean) {\n let order: Order = this.getNextOrder(column.order);\n const beforeEvent = this.emit('beforesorting', { column, order, additive });\n if (beforeEvent.defaultPrevented) {\n return;\n }\n order = beforeEvent.detail.order;\n const newCol = this.providers.column.updateColumnSorting(\n beforeEvent.detail.column,\n index,\n order,\n additive,\n );\n\n // apply sort data\n const beforeApplyEvent = this.emit('beforesortingapply', {\n column: newCol,\n order,\n additive,\n });\n if (beforeApplyEvent.defaultPrevented) {\n return;\n }\n order = beforeApplyEvent.detail.order;\n const cmp = this.getComparer(column, order);\n\n if (additive && this.sorting) {\n const sorting: SortingOrder = {};\n const sortingFunc: SortingOrderFunction = {};\n\n this.sorting = {\n ...this.sorting,\n ...sorting,\n };\n // extend sorting function with new sorting for multiple columns sorting\n this.sortingFunc = {\n ...this.sortingFunc,\n ...sortingFunc,\n };\n\n if (column.prop in sorting && size(sorting) > 1 && order === undefined) {\n delete sorting[column.prop];\n delete sortingFunc[column.prop];\n } else {\n sorting[column.prop] = order;\n sortingFunc[column.prop] = cmp;\n }\n } else {\n if (order) {\n // reset sorting\n this.sorting = { [column.prop]: order };\n this.sortingFunc = { [column.prop]: cmp };\n } else {\n delete this.sorting?.[column.prop];\n delete this.sortingFunc?.[column.prop];\n }\n }\n\n this.startSorting(this.sorting, this.sortingFunc);\n }\n\n /**\n * Sort items by sorting function\n * @requires proxyItems applied to row store\n * @requires source applied to row store\n *\n * @param sorting - per column sorting\n * @param data - this.stores['rgRow'].store.get('source')\n */\n sort(\n sorting?: SortingOrder,\n sortingFunc?: SortingOrderFunction,\n types: DimensionRows[] = rowTypes,\n ) {\n // if no sorting - reset\n if (!size(sorting)) {\n this.sorting = undefined;\n this.sortingFunc = undefined;\n\n for (let type of types) {\n const storeService = this.providers.data.stores[type];\n // row data\n const source = storeService.store.get('source');\n // row indexes\n const proxyItems = storeService.store.get('proxyItems');\n // row indexes\n const newItemsOrder = storeService.store.get('items'); // recover indexes range(0, source.length)\n this.providers.dimension.updateSizesPositionByNewDataIndexes(type, newItemsOrder, proxyItems);\n storeService.setData({ proxyItems: newItemsOrder, source: [...source] });\n }\n } else {\n // set sorting\n this.sorting = sorting;\n this.sortingFunc = sortingFunc;\n\n for (let type of types) {\n const storeService = this.providers.data.stores[type];\n // row data\n const source = storeService.store.get('source');\n // row indexes\n const proxyItems = storeService.store.get('proxyItems');\n\n const newItemsOrder = this.sortIndexByItems(\n [...proxyItems],\n source,\n sortingFunc,\n );\n\n this.providers.dimension.updateSizesPositionByNewDataIndexes(type, newItemsOrder, proxyItems);\n \n storeService.setData({\n proxyItems: newItemsOrder,\n source: [...source],\n });\n }\n }\n this.emit('aftersortingapply');\n }\n\n defaultCellCompare(prop: ColumnProp, a: DataType, b: DataType) {\n const av = a[prop]?.toString().toLowerCase();\n const bv = b[prop]?.toString().toLowerCase();\n\n return av == bv ? 0 : av > bv ? 1 : -1;\n }\n\n descCellCompare(cmp: CellCompareFunc) {\n return (prop: ColumnProp, a: DataType, b: DataType): number => {\n return -1 * cmp(prop, a, b);\n };\n }\n\n sortIndexByItems(\n indexes: number[],\n source: DataType[],\n sortingFunc: SortingOrderFunction = {},\n ): number[] {\n // if no sorting - return unsorted indexes\n if (Object.entries(sortingFunc).length === 0) {\n // Unsorted indexes\n return [...Array(indexes.length).keys()];\n }\n //\n /**\n * go through all indexes and align in new order\n * performs a multi-level sorting by applying multiple comparison functions to determine the order of the items based on different properties.\n */\n return indexes.sort((a, b) => {\n for (const [prop, cmp] of Object.entries(sortingFunc)) {\n const itemA = source[a];\n const itemB = source[b];\n\n /**\n * If the comparison function returns a non-zero value (sorted), it means that the items should be sorted based on the given property. In such a case, the function immediately returns the sorted value, indicating the order in which the items should be arranged.\n * If none of the comparison functions result in a non-zero value, indicating that the items are equal or should remain in the same order, the function eventually returns 0.\n */\n const sorted = cmp?.(prop, itemA, itemB);\n if (sorted) {\n return sorted;\n }\n }\n return 0;\n });\n }\n\n getNextOrder(currentOrder: Order): Order {\n switch (currentOrder) {\n case undefined:\n return 'asc';\n case 'asc':\n return 'desc';\n case 'desc':\n return undefined;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sorting.plugin.js","sourceRoot":"","sources":["../../../src/plugins/sorting/sorting.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAW5C,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAQlC;;;;;;;;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B,EACjB,MAAkB,EAClB,cAAoC,EAAE;QAEtC,0CAA0C;QAC1C,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7C,mBAAmB;YACnB,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QACD,EAAE;QACF;;;WAGG;QACH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC3B,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;gBACtD,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBACxB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAExB;;;mBAGG;gBACH,MAAM,MAAM,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAG,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;gBACzC,IAAI,MAAM,EAAE,CAAC;oBACX,OAAO,MAAM,CAAC;gBAChB,CAAC;YACH,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAC,YAAmB;QAC9B,QAAQ,YAAY,EAAE,CAAC;YACrB,KAAK,SAAS;gBACZ,OAAO,KAAK,CAAC;YACf,KAAK,KAAK;gBACR,OAAO,MAAM,CAAC;YAChB,KAAK,MAAM;gBACT,OAAO,SAAS,CAAC;QACrB,CAAC;IACH,CAAC;CACF","sourcesContent":["import size from 'lodash/size';\nimport debounce from 'lodash/debounce';\n\nimport { BasePlugin } from '../base.plugin';\nimport {\n ColumnProp,\n Order,\n CellCompareFunc,\n ColumnRegular,\n InitialHeaderClick,\n DataType,\n DimensionRows,\n PluginProviders,\n} from '@type';\nimport { getColumnByProp } from '../../utils/column.utils';\nimport { rowTypes } from '@store';\n\nexport type SortingOrder = Record<ColumnProp, Order>;\ntype SortingOrderFunction = Record<ColumnProp, CellCompareFunc | undefined>;\ntype ColumnSetEvent = {\n order: SortingOrder;\n};\n\n/**\n * Lifecycle\n * 1. @event `beforesorting` - Triggered when sorting just starts. Nothing has happened yet. This can be triggered from a column or from the source. If the type is from rows, the column will be undefined.\n * 2. @method `updateColumnSorting` - Updates the column sorting icon on the grid and the column itself, but the data remains untouched.\n * 3. @event `beforesortingapply` - Triggered before the sorting data is applied to the data source. You can prevent this event, and the data will not be sorted. This event is only called from a column sorting click.\n * 4. @event `aftersortingapply` - Triggered after sorting has been applied and completed. This event occurs for both row and column sorting.\n *\n * Note: If you prevent an event, it will not proceed to the subsequent steps.\n */\n\nexport default class SortingPlugin extends BasePlugin {\n // sorting order per column\n sorting?: SortingOrder;\n\n // sorting function per column, multiple columns sorting supported\n sortingFunc?: SortingOrderFunction;\n sortingPromise: (() => void) | null = null;\n postponeSort = debounce(\n (order?: SortingOrder, comparison?: SortingOrderFunction) =>\n this.runSorting(order, comparison),\n 50,\n );\n\n runSorting(\n order?: SortingOrder,\n comparison?: SortingOrderFunction,\n ) {\n this.sort(order, comparison);\n this.sortingPromise?.();\n this.sortingPromise = null;\n }\n\n constructor(\n public revogrid: HTMLRevoGridElement,\n providers: PluginProviders,\n ) {\n super(revogrid, providers);\n\n const beforeanysource = ({\n detail: { type },\n }: CustomEvent<{\n type: DimensionRows;\n source: any[];\n }>) => {\n // if sorting was provided - sort data\n if (!!this.sorting && this.sortingFunc) {\n const beforeEvent = this.emit('beforesorting', { type });\n if (beforeEvent.defaultPrevented) {\n return;\n }\n this.startSorting(this.sorting, this.sortingFunc);\n }\n };\n const aftercolumnsset = ({\n detail: { order },\n }: CustomEvent<ColumnSetEvent>) => {\n const columns = this.providers.column.getColumns();\n const sortingFunc: SortingOrderFunction = {};\n\n for (let prop in order) {\n const cmp = this.getComparer(\n getColumnByProp(columns, prop),\n order[prop],\n );\n sortingFunc[prop] = cmp;\n }\n this.runSorting(order, sortingFunc);\n };\n const headerclick = (e: CustomEvent<InitialHeaderClick>) => {\n if (e.defaultPrevented) {\n return;\n }\n\n if (!e.detail.column.sortable) {\n return;\n }\n\n this.headerclick(\n e.detail.column,\n e.detail.index,\n e.detail?.originalEvent?.shiftKey,\n );\n };\n\n this.addEventListener('beforeanysource', beforeanysource);\n this.addEventListener('aftercolumnsset', aftercolumnsset);\n this.addEventListener('beforeheaderclick', headerclick);\n }\n\n startSorting(order?: SortingOrder, sortingFunc?: SortingOrderFunction) {\n if (!this.sortingPromise) {\n this.revogrid.jobsBeforeRender.push(\n new Promise<void>(resolve => {\n this.sortingPromise = resolve;\n }),\n );\n }\n this.postponeSort(order, sortingFunc);\n }\n\n getComparer(column: ColumnRegular | undefined, order: Order): CellCompareFunc | undefined {\n const cellCmp: CellCompareFunc =\n column?.cellCompare?.bind({ order }) || this.defaultCellCompare;\n if (order == 'asc') {\n return cellCmp;\n }\n if (order == 'desc') {\n return this.descCellCompare(cellCmp);\n }\n return undefined;\n }\n\n /**\n * Apply sorting to data on header click\n * If additive - add to existing sorting, multiple columns can be sorted\n */\n headerclick(column: ColumnRegular, index: number, additive: boolean) {\n let order: Order = this.getNextOrder(column.order);\n const beforeEvent = this.emit('beforesorting', { column, order, additive });\n if (beforeEvent.defaultPrevented) {\n return;\n }\n order = beforeEvent.detail.order;\n const newCol = this.providers.column.updateColumnSorting(\n beforeEvent.detail.column,\n index,\n order,\n additive,\n );\n\n // apply sort data\n const beforeApplyEvent = this.emit('beforesortingapply', {\n column: newCol,\n order,\n additive,\n });\n if (beforeApplyEvent.defaultPrevented) {\n return;\n }\n order = beforeApplyEvent.detail.order;\n const cmp = this.getComparer(column, order);\n\n if (additive && this.sorting) {\n const sorting: SortingOrder = {};\n const sortingFunc: SortingOrderFunction = {};\n\n this.sorting = {\n ...this.sorting,\n ...sorting,\n };\n // extend sorting function with new sorting for multiple columns sorting\n this.sortingFunc = {\n ...this.sortingFunc,\n ...sortingFunc,\n };\n\n if (column.prop in sorting && size(sorting) > 1 && order === undefined) {\n delete sorting[column.prop];\n delete sortingFunc[column.prop];\n } else {\n sorting[column.prop] = order;\n sortingFunc[column.prop] = cmp;\n }\n } else {\n if (order) {\n // reset sorting\n this.sorting = { [column.prop]: order };\n this.sortingFunc = { [column.prop]: cmp };\n } else {\n delete this.sorting?.[column.prop];\n delete this.sortingFunc?.[column.prop];\n }\n }\n\n this.startSorting(this.sorting, this.sortingFunc);\n }\n\n /**\n * Sort items by sorting function\n * @requires proxyItems applied to row store\n * @requires source applied to row store\n *\n * @param sorting - per column sorting\n * @param data - this.stores['rgRow'].store.get('source')\n */\n sort(\n sorting?: SortingOrder,\n sortingFunc?: SortingOrderFunction,\n types: DimensionRows[] = rowTypes,\n ) {\n // if no sorting - reset\n if (!size(sorting)) {\n this.sorting = undefined;\n this.sortingFunc = undefined;\n\n for (let type of types) {\n const storeService = this.providers.data.stores[type];\n // row data\n const source = storeService.store.get('source');\n // row indexes\n const proxyItems = storeService.store.get('proxyItems');\n // row indexes\n const newItemsOrder = storeService.store.get('items'); // recover indexes range(0, source.length)\n this.providers.dimension.updateSizesPositionByNewDataIndexes(type, newItemsOrder, proxyItems);\n storeService.setData({ proxyItems: newItemsOrder, source: [...source] });\n }\n } else {\n // set sorting\n this.sorting = sorting;\n this.sortingFunc = sortingFunc;\n\n for (let type of types) {\n const storeService = this.providers.data.stores[type];\n // row data\n const source = storeService.store.get('source');\n // row indexes\n const proxyItems = storeService.store.get('proxyItems');\n\n const newItemsOrder = this.sortIndexByItems(\n [...proxyItems],\n source,\n sortingFunc,\n );\n\n this.providers.dimension.updateSizesPositionByNewDataIndexes(type, newItemsOrder, proxyItems);\n \n storeService.setData({\n proxyItems: newItemsOrder,\n source: [...source],\n });\n }\n }\n this.emit('aftersortingapply');\n }\n\n defaultCellCompare(prop: ColumnProp, a: DataType, b: DataType) {\n const av = a?.[prop]?.toString().toLowerCase();\n const bv = b?.[prop]?.toString().toLowerCase();\n\n return av == bv ? 0 : av > bv ? 1 : -1;\n }\n\n descCellCompare(cmp: CellCompareFunc) {\n return (prop: ColumnProp, a: DataType, b: DataType): number => {\n return -1 * cmp(prop, a, b);\n };\n }\n\n sortIndexByItems(\n indexes: number[],\n source: DataType[],\n sortingFunc: SortingOrderFunction = {},\n ): number[] {\n // if no sorting - return unsorted indexes\n if (Object.entries(sortingFunc).length === 0) {\n // Unsorted indexes\n return [...Array(indexes.length).keys()];\n }\n //\n /**\n * go through all indexes and align in new order\n * performs a multi-level sorting by applying multiple comparison functions to determine the order of the items based on different properties.\n */\n return indexes.sort((a, b) => {\n for (const [prop, cmp] of Object.entries(sortingFunc)) {\n const itemA = source[a];\n const itemB = source[b];\n\n /**\n * If the comparison function returns a non-zero value (sorted), it means that the items should be sorted based on the given property. In such a case, the function immediately returns the sorted value, indicating the order in which the items should be arranged.\n * If none of the comparison functions result in a non-zero value, indicating that the items are equal or should remain in the same order, the function eventually returns 0.\n */\n const sorted = cmp?.(prop, itemA, itemB);\n if (sorted) {\n return sorted;\n }\n }\n return 0;\n });\n }\n\n getNextOrder(currentOrder: Order): Order {\n switch (currentOrder) {\n case undefined:\n return 'asc';\n case 'asc':\n return 'desc';\n case 'desc':\n return undefined;\n }\n }\n}\n"]}
|
|
@@ -773,8 +773,8 @@ class SortingPlugin extends BasePlugin {
|
|
|
773
773
|
}
|
|
774
774
|
defaultCellCompare(prop, a, b) {
|
|
775
775
|
var _a, _b;
|
|
776
|
-
const av = (_a = a[prop]) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase();
|
|
777
|
-
const bv = (_b = b[prop]) === null || _b === void 0 ? void 0 : _b.toString().toLowerCase();
|
|
776
|
+
const av = (_a = a === null || a === void 0 ? void 0 : a[prop]) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase();
|
|
777
|
+
const bv = (_b = b === null || b === void 0 ? void 0 : b[prop]) === null || _b === void 0 ? void 0 : _b.toString().toLowerCase();
|
|
778
778
|
return av == bv ? 0 : av > bv ? 1 : -1;
|
|
779
779
|
}
|
|
780
780
|
descCellCompare(cmp) {
|