@tanstack/table-core 8.0.0-alpha.86 → 8.0.0-alpha.87
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/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/sortingFns.js +53 -51
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/esm/index.js +53 -51
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +308 -308
- package/build/types/features/Sorting.d.ts +3 -3
- package/build/types/sortingFns.d.ts +7 -14
- package/build/umd/index.development.js +53 -51
- 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/features/Sorting.ts +4 -4
- package/src/sortingFns.ts +59 -81
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.87",
|
|
5
5
|
"description": "Hooks for building lightweight, fast and extendable datagrids for React",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/react-table#readme",
|
package/src/features/Sorting.ts
CHANGED
|
@@ -26,6 +26,10 @@ export type ColumnSort = {
|
|
|
26
26
|
|
|
27
27
|
export type SortingState = ColumnSort[]
|
|
28
28
|
|
|
29
|
+
export type SortingTableState = {
|
|
30
|
+
sorting: SortingState
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
export type SortingFn<TGenerics extends TableGenerics> = {
|
|
30
34
|
(rowA: Row<TGenerics>, rowB: Row<TGenerics>, columnId: string): number
|
|
31
35
|
}
|
|
@@ -35,10 +39,6 @@ export type CustomSortingFns<TGenerics extends TableGenerics> = Record<
|
|
|
35
39
|
SortingFn<TGenerics>
|
|
36
40
|
>
|
|
37
41
|
|
|
38
|
-
export type SortingTableState = {
|
|
39
|
-
sorting: SortingState
|
|
40
|
-
}
|
|
41
|
-
|
|
42
42
|
export type SortingFnOption<TGenerics extends TableGenerics> =
|
|
43
43
|
| 'auto'
|
|
44
44
|
| BuiltInSortingFn
|
package/src/sortingFns.ts
CHANGED
|
@@ -1,40 +1,69 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SortingFn } from './features/Sorting'
|
|
2
2
|
|
|
3
3
|
export const reSplitAlphaNumeric = /([0-9]+)/gm
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
datetime,
|
|
11
|
-
basic,
|
|
5
|
+
const alphanumeric: SortingFn<any> = (rowA, rowB, columnId) => {
|
|
6
|
+
return compareAlphanumeric(
|
|
7
|
+
toString(rowA.getValue(columnId)).toLowerCase(),
|
|
8
|
+
toString(rowB.getValue(columnId)).toLowerCase()
|
|
9
|
+
)
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function alphanumeric<TGenerics extends TableGenerics>(
|
|
17
|
-
rowA: Row<TGenerics>,
|
|
18
|
-
rowB: Row<TGenerics>,
|
|
19
|
-
columnId: string
|
|
20
|
-
) {
|
|
12
|
+
const alphanumericCaseSensitive: SortingFn<any> = (rowA, rowB, columnId) => {
|
|
21
13
|
return compareAlphanumeric(
|
|
14
|
+
toString(rowA.getValue(columnId)),
|
|
15
|
+
toString(rowB.getValue(columnId))
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// The text filter is more basic (less numeric support)
|
|
20
|
+
// but is much faster
|
|
21
|
+
const text: SortingFn<any> = (rowA, rowB, columnId) => {
|
|
22
|
+
return compareBasic(
|
|
22
23
|
toString(rowA.getValue(columnId)).toLowerCase(),
|
|
23
24
|
toString(rowB.getValue(columnId)).toLowerCase()
|
|
24
25
|
)
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
) {
|
|
32
|
-
return compareAlphanumeric(
|
|
28
|
+
// The text filter is more basic (less numeric support)
|
|
29
|
+
// but is much faster
|
|
30
|
+
const textCaseSensitive: SortingFn<any> = (rowA, rowB, columnId) => {
|
|
31
|
+
return compareBasic(
|
|
33
32
|
toString(rowA.getValue(columnId)),
|
|
34
33
|
toString(rowB.getValue(columnId))
|
|
35
34
|
)
|
|
36
35
|
}
|
|
37
36
|
|
|
37
|
+
const datetime: SortingFn<any> = (rowA, rowB, columnId) => {
|
|
38
|
+
return compareBasic(
|
|
39
|
+
(rowA.getValue(columnId) as Date).getTime(),
|
|
40
|
+
(rowB.getValue(columnId) as Date).getTime()
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const basic: SortingFn<any> = (rowA, rowB, columnId) => {
|
|
45
|
+
return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Utils
|
|
49
|
+
|
|
50
|
+
function compareBasic(a: any, b: any) {
|
|
51
|
+
return a === b ? 0 : a > b ? 1 : -1
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function toString(a: any) {
|
|
55
|
+
if (typeof a === 'number') {
|
|
56
|
+
if (isNaN(a) || a === Infinity || a === -Infinity) {
|
|
57
|
+
return ''
|
|
58
|
+
}
|
|
59
|
+
return String(a)
|
|
60
|
+
}
|
|
61
|
+
if (typeof a === 'string') {
|
|
62
|
+
return a
|
|
63
|
+
}
|
|
64
|
+
return ''
|
|
65
|
+
}
|
|
66
|
+
|
|
38
67
|
// Mixed sorting is slow, but very inclusive of many edge cases.
|
|
39
68
|
// It handles numbers, mixed alphanumeric combinations, and even
|
|
40
69
|
// null, undefined, and Infinity
|
|
@@ -82,66 +111,15 @@ function compareAlphanumeric(aStr: string, bStr: string) {
|
|
|
82
111
|
return a.length - b.length
|
|
83
112
|
}
|
|
84
113
|
|
|
85
|
-
//
|
|
86
|
-
// but is much faster
|
|
87
|
-
function text<TGenerics extends TableGenerics>(
|
|
88
|
-
rowA: Row<TGenerics>,
|
|
89
|
-
rowB: Row<TGenerics>,
|
|
90
|
-
columnId: string
|
|
91
|
-
) {
|
|
92
|
-
return compareBasic(
|
|
93
|
-
toString(rowA.getValue(columnId)).toLowerCase(),
|
|
94
|
-
toString(rowB.getValue(columnId)).toLowerCase()
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// The text filter is more basic (less numeric support)
|
|
99
|
-
// but is much faster
|
|
100
|
-
function textCaseSensitive<TGenerics extends TableGenerics>(
|
|
101
|
-
rowA: Row<TGenerics>,
|
|
102
|
-
rowB: Row<TGenerics>,
|
|
103
|
-
columnId: string
|
|
104
|
-
) {
|
|
105
|
-
return compareBasic(
|
|
106
|
-
toString(rowA.getValue(columnId)),
|
|
107
|
-
toString(rowB.getValue(columnId))
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function datetime<TGenerics extends TableGenerics>(
|
|
112
|
-
rowA: Row<TGenerics>,
|
|
113
|
-
rowB: Row<TGenerics>,
|
|
114
|
-
columnId: string
|
|
115
|
-
) {
|
|
116
|
-
return compareBasic(
|
|
117
|
-
(rowA.getValue(columnId) as Date).getTime(),
|
|
118
|
-
(rowB.getValue(columnId) as Date).getTime()
|
|
119
|
-
)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function basic<TGenerics extends TableGenerics>(
|
|
123
|
-
rowA: Row<TGenerics>,
|
|
124
|
-
rowB: Row<TGenerics>,
|
|
125
|
-
columnId: string
|
|
126
|
-
) {
|
|
127
|
-
return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId))
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Utils
|
|
114
|
+
// Exports
|
|
131
115
|
|
|
132
|
-
|
|
133
|
-
|
|
116
|
+
export const sortingFns = {
|
|
117
|
+
alphanumeric,
|
|
118
|
+
alphanumericCaseSensitive,
|
|
119
|
+
text,
|
|
120
|
+
textCaseSensitive,
|
|
121
|
+
datetime,
|
|
122
|
+
basic,
|
|
134
123
|
}
|
|
135
124
|
|
|
136
|
-
|
|
137
|
-
if (typeof a === 'number') {
|
|
138
|
-
if (isNaN(a) || a === Infinity || a === -Infinity) {
|
|
139
|
-
return ''
|
|
140
|
-
}
|
|
141
|
-
return String(a)
|
|
142
|
-
}
|
|
143
|
-
if (typeof a === 'string') {
|
|
144
|
-
return a
|
|
145
|
-
}
|
|
146
|
-
return ''
|
|
147
|
-
}
|
|
125
|
+
export type BuiltInSortingFn = keyof typeof sortingFns
|