From 977d6f180f0c5391ddd83396376976c4bfa88e59 Mon Sep 17 00:00:00 2001 From: maks Date: Tue, 19 Nov 2024 22:14:17 +0000 Subject: [PATCH] sorting extracted --- docs | 2 +- package-lock.json | 4 +-- packages/angular | 2 +- packages/react | 2 +- packages/svelte | 2 +- packages/vue2 | 2 +- packages/vue3 | 2 +- src/components.d.ts | 5 ++++ src/components/revoGrid/revo-grid.tsx | 9 +++++- src/plugins/sorting/sorting.func.ts | 35 ++++++++++++++++++++++ src/plugins/sorting/sorting.plugin.ts | 43 ++------------------------- src/plugins/sorting/sorting.types.ts | 10 +++++++ src/types/events.ts | 2 ++ 13 files changed, 71 insertions(+), 49 deletions(-) create mode 100644 src/plugins/sorting/sorting.func.ts create mode 100644 src/plugins/sorting/sorting.types.ts diff --git a/docs b/docs index 9825b688..4192f509 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 9825b688ceacb195cdad228d2a189d5bfb4bb256 +Subproject commit 4192f509646b5b203949a65e785a23eede0fc8ee diff --git a/package-lock.json b/package-lock.json index 62e0b903..d2251642 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@revolist/revogrid", - "version": "4.10.20", + "version": "4.10.30", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@revolist/revogrid", - "version": "4.10.20", + "version": "4.10.30", "license": "MIT", "devDependencies": { "@angular/core": "^18.1.2", diff --git a/packages/angular b/packages/angular index 57549cda..8069ca8a 160000 --- a/packages/angular +++ b/packages/angular @@ -1 +1 @@ -Subproject commit 57549cdac30f4b52662423d2eff620c28625b3ee +Subproject commit 8069ca8aa3893c83a935ba6399aaefa727f41ffd diff --git a/packages/react b/packages/react index fe515a9e..4c9dc829 160000 --- a/packages/react +++ b/packages/react @@ -1 +1 @@ -Subproject commit fe515a9e2f6f97ffaabe80a8e726c2f4e2f36a29 +Subproject commit 4c9dc8295cab229aabe83261c456f72dc612596c diff --git a/packages/svelte b/packages/svelte index 3f79a4fb..6e1ef21e 160000 --- a/packages/svelte +++ b/packages/svelte @@ -1 +1 @@ -Subproject commit 3f79a4fb63feec91af2096e4477564cef0c70cda +Subproject commit 6e1ef21e2a56d8e1f8b2c95c4630af39d07c5577 diff --git a/packages/vue2 b/packages/vue2 index fa2c67e6..8fe2eebe 160000 --- a/packages/vue2 +++ b/packages/vue2 @@ -1 +1 @@ -Subproject commit fa2c67e6545a0d055c0b35f94583083149eee9a9 +Subproject commit 8fe2eebee47dbc944b28fa4e5d1827d3400e2432 diff --git a/packages/vue3 b/packages/vue3 index 9ca46960..55ef40b1 160000 --- a/packages/vue3 +++ b/packages/vue3 @@ -1 +1 @@ -Subproject commit 9ca46960afc0ad9658ec60fc195788420dca505c +Subproject commit 55ef40b1564e485de38213e4ca0020cf934fdc32 diff --git a/src/components.d.ts b/src/components.d.ts index 08333b79..b74a77d6 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -846,6 +846,7 @@ declare global { "aftergridinit": any; "additionaldatachanged": any; "afterthemechanged": Theme; + "created": any; } /** * Revogrid - High-performance, customizable grid library for managing large datasets. @@ -1497,6 +1498,10 @@ declare namespace LocalJSX { * New content size has been applied. The size excludes the header. Currently, the event responsible for applying the new content size does not provide the actual size. To retrieve the actual content size, you can utilize the `getContentSize` function after the event has been triggered. */ "onContentsizechanged"?: (event: RevoGridCustomEvent) => void; + /** + * Emmited after grid created + */ + "onCreated"?: (event: RevoGridCustomEvent) => void; /** * Emitted when the filter configuration is changed */ diff --git a/src/components/revoGrid/revo-grid.tsx b/src/components/revoGrid/revo-grid.tsx index 45d7402b..56baed37 100644 --- a/src/components/revoGrid/revo-grid.tsx +++ b/src/components/revoGrid/revo-grid.tsx @@ -561,7 +561,13 @@ export class RevoGridComponent { /** * Emmited after the theme is changed */ - @Event() afterthemechanged: EventEmitter + @Event() afterthemechanged: EventEmitter; + + + /** + * Emmited after grid created + */ + @Event() created: EventEmitter; // #endregion @@ -1409,6 +1415,7 @@ export class RevoGridComponent { if (this.isInited) { this.setPlugins(); } + this.created.emit(); } /** diff --git a/src/plugins/sorting/sorting.func.ts b/src/plugins/sorting/sorting.func.ts new file mode 100644 index 00000000..2204b5cb --- /dev/null +++ b/src/plugins/sorting/sorting.func.ts @@ -0,0 +1,35 @@ +import type { DataType } from '@type'; +import type { SortingOrderFunction } from './sorting.types'; + +export function sortIndexByItems( + indexes: number[], + source: DataType[], + sortingFunc: SortingOrderFunction = {}, +): number[] { + // if no sorting - return unsorted indexes + if (Object.entries(sortingFunc).length === 0) { + // Unsorted indexes + return [...Array(indexes.length).keys()]; + } + // + /** + * go through all indexes and align in new order + * performs a multi-level sorting by applying multiple comparison functions to determine the order of the items based on different properties. + */ + return indexes.sort((a, b) => { + for (const [prop, cmp] of Object.entries(sortingFunc)) { + const itemA = source[a]; + const itemB = source[b]; + + /** + * 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. + * 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. + */ + const sorted = cmp?.(prop, itemA, itemB); + if (sorted) { + return sorted; + } + } + return 0; + }); +} diff --git a/src/plugins/sorting/sorting.plugin.ts b/src/plugins/sorting/sorting.plugin.ts index 8e571eb1..fdb0c610 100644 --- a/src/plugins/sorting/sorting.plugin.ts +++ b/src/plugins/sorting/sorting.plugin.ts @@ -12,14 +12,10 @@ import type { DimensionRows, PluginProviders, } from '@type'; +import type { SortingOrder, SortingOrderFunction, ColumnSetEvent } from './sorting.types'; import { getCellRaw, getColumnByProp } from '../../utils/column.utils'; import { rowTypes } from '@store'; - -export type SortingOrder = Record; -type SortingOrderFunction = Record; -type ColumnSetEvent = { - order: SortingOrder; -}; +import { sortIndexByItems } from './sorting.func'; /** * Lifecycle @@ -239,7 +235,7 @@ export class SortingPlugin extends BasePlugin { // row indexes const proxyItems = storeService.store.get('proxyItems'); - const newItemsOrder = this.sortIndexByItems( + const newItemsOrder = sortIndexByItems( [...proxyItems], source, sortingFunc, @@ -274,39 +270,6 @@ export class SortingPlugin extends BasePlugin { }; } - sortIndexByItems( - indexes: number[], - source: DataType[], - sortingFunc: SortingOrderFunction = {}, - ): number[] { - // if no sorting - return unsorted indexes - if (Object.entries(sortingFunc).length === 0) { - // Unsorted indexes - return [...Array(indexes.length).keys()]; - } - // - /** - * go through all indexes and align in new order - * performs a multi-level sorting by applying multiple comparison functions to determine the order of the items based on different properties. - */ - return indexes.sort((a, b) => { - for (const [prop, cmp] of Object.entries(sortingFunc)) { - const itemA = source[a]; - const itemB = source[b]; - - /** - * 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. - * 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. - */ - const sorted = cmp?.(prop, itemA, itemB); - if (sorted) { - return sorted; - } - } - return 0; - }); - } - getNextOrder(currentOrder: Order): Order { switch (currentOrder) { case undefined: diff --git a/src/plugins/sorting/sorting.types.ts b/src/plugins/sorting/sorting.types.ts new file mode 100644 index 00000000..6ea3df7e --- /dev/null +++ b/src/plugins/sorting/sorting.types.ts @@ -0,0 +1,10 @@ +import type { CellCompareFunc, ColumnProp, Order } from '@type'; + +export type SortingOrder = Record; +export type SortingOrderFunction = Record< + ColumnProp, + CellCompareFunc | undefined +>; +export type ColumnSetEvent = { + order: SortingOrder; +}; diff --git a/src/types/events.ts b/src/types/events.ts index 61bbfc39..f947444f 100644 --- a/src/types/events.ts +++ b/src/types/events.ts @@ -36,6 +36,7 @@ export type RevogridEvents = 'contentsizechanged'| 'aftergridinit'| 'additionaldatachanged'| 'afterthemechanged'| + 'created'| 'beforepaste'| 'beforepasteapply'| 'pasteregion'| @@ -140,6 +141,7 @@ export const REVOGRID_EVENTS = new Map([ ['aftergridinit', 'aftergridinit'], ['additionaldatachanged', 'additionaldatachanged'], ['afterthemechanged', 'afterthemechanged'], + ['created', 'created'], ['beforepaste', 'beforepaste'], ['beforepasteapply', 'beforepasteapply'], ['pasteregion', 'pasteregion'],