-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #637 from revolist/minor-refactor
Sorting extracted outside
- Loading branch information
Showing
13 changed files
with
71 additions
and
49 deletions.
There are no files selected for viewing
Submodule docs
updated
29 files
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Submodule angular
updated
3 files
+2 −2 | package.json | |
+2 −2 | projects/angular-datagrid/package.json | |
+2 −2 | projects/angular-datagrid/src/lib/components.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { CellCompareFunc, ColumnProp, Order } from '@type'; | ||
|
||
export type SortingOrder = Record<ColumnProp, Order>; | ||
export type SortingOrderFunction = Record< | ||
ColumnProp, | ||
CellCompareFunc | undefined | ||
>; | ||
export type ColumnSetEvent = { | ||
order: SortingOrder; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters