@tanstack/table-core 8.9.0 → 8.9.2
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/build/lib/aggregationFns.js +12 -10
- package/build/lib/aggregationFns.js.map +1 -1
- package/build/lib/index.esm.js +19 -12
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +1 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +19 -12
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/utils/getSortedRowModel.js +5 -1
- package/build/lib/utils/getSortedRowModel.js.map +1 -1
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.js +4 -0
- package/build/lib/utils.js.map +1 -1
- package/build/umd/index.development.js +19 -11
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/aggregationFns.ts +11 -11
- package/src/utils/getSortedRowModel.ts +12 -5
- package/src/utils.ts +4 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.9.
|
|
4
|
+
"version": "8.9.2",
|
|
5
5
|
"description": "Headless UI for building powerful tables & datagrids for TS/JS.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/table#readme",
|
package/src/aggregationFns.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AggregationFn } from './features/Grouping'
|
|
2
|
+
import { isNumberArray } from './utils'
|
|
2
3
|
|
|
3
4
|
const sum: AggregationFn<any> = (columnId, _leafRows, childRows) => {
|
|
4
5
|
// It's faster to just add the aggregations together instead of
|
|
@@ -82,18 +83,17 @@ const median: AggregationFn<any> = (columnId, leafRows) => {
|
|
|
82
83
|
return
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
max = Math.max(max, value)
|
|
93
|
-
}
|
|
94
|
-
})
|
|
86
|
+
const values = leafRows.map(row => row.getValue(columnId))
|
|
87
|
+
if (!isNumberArray(values)) {
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
if (values.length === 1) {
|
|
91
|
+
return values[0]
|
|
92
|
+
}
|
|
95
93
|
|
|
96
|
-
|
|
94
|
+
const mid = Math.floor(values.length / 2)
|
|
95
|
+
const nums = values.sort((a, b) => a - b)
|
|
96
|
+
return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1]! + nums[mid]!) / 2
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
const unique: AggregationFn<any> = (columnId, leafRows) => {
|
|
@@ -61,11 +61,18 @@ export function getSortedRowModel<TData extends RowData>(): (
|
|
|
61
61
|
const bUndefined = typeof bValue === 'undefined'
|
|
62
62
|
|
|
63
63
|
if (aUndefined || bUndefined) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
let undefinedSort =
|
|
65
|
+
aUndefined && bUndefined
|
|
66
|
+
? 0
|
|
67
|
+
: aUndefined
|
|
68
|
+
? columnInfo.sortUndefined
|
|
69
|
+
: -columnInfo.sortUndefined
|
|
70
|
+
|
|
71
|
+
if (isDesc && undefinedSort !== 0) {
|
|
72
|
+
undefinedSort *= -1
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return undefinedSort
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
78
|
|
package/src/utils.ts
CHANGED
|
@@ -103,6 +103,10 @@ export function isFunction<T extends AnyFunction>(d: any): d is T {
|
|
|
103
103
|
return d instanceof Function
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
export function isNumberArray(d: any): d is number[] {
|
|
107
|
+
return Array.isArray(d) && d.every(val => typeof val === 'number')
|
|
108
|
+
}
|
|
109
|
+
|
|
106
110
|
export function flattenBy<TNode>(
|
|
107
111
|
arr: TNode[],
|
|
108
112
|
getChildren: (item: TNode) => TNode[]
|