@tanstack/table-core 8.0.0-alpha.45 → 8.0.0-alpha.48
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/aggregationFns.js.map +1 -1
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +6 -6
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +2 -2
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/RowSelection.js +2 -2
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +2 -2
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js.map +1 -1
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/esm/index.js +12 -12
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +296 -296
- package/build/types/aggregationFns.d.ts +1 -1
- package/build/types/createTable.d.ts +7 -7
- package/build/types/features/Expanding.d.ts +1 -1
- package/build/types/features/Filters.d.ts +6 -6
- package/build/types/features/Grouping.d.ts +6 -6
- package/build/types/features/RowSelection.d.ts +1 -1
- package/build/types/features/Sorting.d.ts +7 -7
- package/build/types/filterFns.d.ts +1 -1
- package/build/types/sortingFns.d.ts +1 -1
- package/build/umd/index.development.js +12 -12
- 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 +1 -1
- package/src/createTable.ts +9 -11
- package/src/features/ColumnSizing.ts +4 -4
- package/src/features/Expanding.ts +3 -3
- package/src/features/Filters.ts +18 -18
- package/src/features/Grouping.ts +11 -11
- package/src/features/RowSelection.ts +13 -11
- package/src/features/Sorting.ts +18 -14
- package/src/features/Visibility.ts +4 -2
- package/src/filterFns.ts +1 -1
- package/src/sortingFns.ts +2 -2
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.48",
|
|
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/aggregationFns.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const aggregationFns = {
|
|
|
10
10
|
count,
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type BuiltInAggregationFn = keyof typeof aggregationFns
|
|
14
14
|
|
|
15
15
|
function sum(_getLeafValues: () => unknown[], getChildValues: () => unknown[]) {
|
|
16
16
|
// It's faster to just add the aggregations together instead of
|
package/src/createTable.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AggregationFn,
|
|
3
|
-
import {
|
|
1
|
+
import { CustomFilterFns, FilterFn } from './features/Filters'
|
|
2
|
+
import { AggregationFn, CustomAggregationFns } from './features/Grouping'
|
|
3
|
+
import { CustomSortingFns, SortingFn } from './features/Sorting'
|
|
4
4
|
import { ColumnDef, AccessorFn, AnyRender, AnyGenerics, Options } from './types'
|
|
5
5
|
import { IfDefined, Overwrite, PartialKeys } from './utils'
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ export type TableFactory<TGenerics extends AnyGenerics> = () => Table<TGenerics>
|
|
|
8
8
|
|
|
9
9
|
export type CreateTableOptions<
|
|
10
10
|
TRender extends AnyRender,
|
|
11
|
-
TFilterFns extends
|
|
12
|
-
TSortingFns extends
|
|
13
|
-
TAggregationFns extends
|
|
11
|
+
TFilterFns extends CustomFilterFns<any>,
|
|
12
|
+
TSortingFns extends CustomSortingFns<any>,
|
|
13
|
+
TAggregationFns extends CustomAggregationFns<any>,
|
|
14
14
|
TGenerics extends AnyGenerics
|
|
15
15
|
> = Partial<
|
|
16
16
|
{
|
|
@@ -24,13 +24,11 @@ export type CreateTableOptions<
|
|
|
24
24
|
export type Table<TGenerics extends AnyGenerics> = {
|
|
25
25
|
generics: TGenerics
|
|
26
26
|
options: Partial<Options<TGenerics>>
|
|
27
|
-
setRowType: <TRow
|
|
28
|
-
|
|
29
|
-
>
|
|
30
|
-
setTableMetaType: <TTableMeta extends object>() => Table<
|
|
27
|
+
setRowType: <TRow>() => Table<Overwrite<TGenerics, { Row: TRow }>>
|
|
28
|
+
setTableMetaType: <TTableMeta>() => Table<
|
|
31
29
|
Overwrite<TGenerics, { TableMeta: TTableMeta }>
|
|
32
30
|
>
|
|
33
|
-
setColumnMetaType: <TColumnMeta
|
|
31
|
+
setColumnMetaType: <TColumnMeta>() => Table<
|
|
34
32
|
Overwrite<TGenerics, { ColumnMeta: TColumnMeta }>
|
|
35
33
|
>
|
|
36
34
|
setOptions: <
|
|
@@ -228,7 +228,7 @@ export const ColumnSizing = {
|
|
|
228
228
|
|
|
229
229
|
const canResize = column.getCanResize()
|
|
230
230
|
|
|
231
|
-
const onResizeStart = (e:
|
|
231
|
+
const onResizeStart = (e: unknown) => {
|
|
232
232
|
if (isTouchStartEvent(e)) {
|
|
233
233
|
// lets not respond to multiple touches (e.g. 2 or 3 fingers)
|
|
234
234
|
if (e.touches && e.touches.length > 1) {
|
|
@@ -246,7 +246,7 @@ export const ColumnSizing = {
|
|
|
246
246
|
|
|
247
247
|
const clientX = isTouchStartEvent(e)
|
|
248
248
|
? Math.round(e.touches[0].clientX)
|
|
249
|
-
: e.clientX
|
|
249
|
+
: (e as MouseEvent).clientX
|
|
250
250
|
|
|
251
251
|
const updateOffset = (
|
|
252
252
|
eventType: 'move' | 'end',
|
|
@@ -446,6 +446,6 @@ export function passiveEventSupported() {
|
|
|
446
446
|
return passiveSupported
|
|
447
447
|
}
|
|
448
448
|
|
|
449
|
-
function isTouchStartEvent(e:
|
|
450
|
-
return e.type === 'touchstart'
|
|
449
|
+
function isTouchStartEvent(e: unknown): e is TouchEvent {
|
|
450
|
+
return (e as TouchEvent).type === 'touchstart'
|
|
451
451
|
}
|
|
@@ -42,7 +42,7 @@ export type ExpandedOptions<TGenerics extends AnyGenerics> = {
|
|
|
42
42
|
|
|
43
43
|
export type ToggleExpandedProps = {
|
|
44
44
|
title?: string
|
|
45
|
-
onClick?: (event:
|
|
45
|
+
onClick?: (event: unknown) => void
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export type ExpandedInstance<TGenerics extends AnyGenerics> = {
|
|
@@ -217,7 +217,7 @@ export const Expanding = {
|
|
|
217
217
|
const initialProps: ToggleExpandedProps = {
|
|
218
218
|
title: canExpand ? 'Toggle Expanded' : undefined,
|
|
219
219
|
onClick: canExpand
|
|
220
|
-
? (e:
|
|
220
|
+
? (e: unknown) => {
|
|
221
221
|
;(e as any).persist?.()
|
|
222
222
|
instance.toggleRowExpanded(rowId)
|
|
223
223
|
}
|
|
@@ -229,7 +229,7 @@ export const Expanding = {
|
|
|
229
229
|
getToggleAllRowsExpandedProps: userProps => {
|
|
230
230
|
const initialProps: ToggleExpandedProps = {
|
|
231
231
|
title: 'Toggle All Expanded',
|
|
232
|
-
onClick: (e:
|
|
232
|
+
onClick: (e: unknown) => {
|
|
233
233
|
;(e as any).persist?.()
|
|
234
234
|
instance.toggleAllRowsExpanded()
|
|
235
235
|
},
|
package/src/features/Filters.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RowModel } from '..'
|
|
2
|
-
import {
|
|
2
|
+
import { BuiltInFilterFn, filterFns } from '../filterFns'
|
|
3
3
|
import {
|
|
4
4
|
Column,
|
|
5
5
|
OnChangeFn,
|
|
@@ -34,7 +34,7 @@ export type ColumnFilterAutoRemoveTestFn<TGenerics extends AnyGenerics> = (
|
|
|
34
34
|
column?: Column<TGenerics>
|
|
35
35
|
) => boolean
|
|
36
36
|
|
|
37
|
-
export type
|
|
37
|
+
export type CustomFilterFns<TGenerics extends AnyGenerics> = Record<
|
|
38
38
|
string,
|
|
39
39
|
FilterFn<TGenerics>
|
|
40
40
|
>
|
|
@@ -46,14 +46,14 @@ export type FiltersTableState = {
|
|
|
46
46
|
globalFilterProgress: number
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export type
|
|
49
|
+
export type FilterFnOption<TGenerics extends AnyGenerics> =
|
|
50
50
|
| 'auto'
|
|
51
|
-
|
|
|
51
|
+
| BuiltInFilterFn
|
|
52
52
|
| keyof TGenerics['FilterFns']
|
|
53
53
|
| FilterFn<TGenerics>
|
|
54
54
|
|
|
55
55
|
export type FiltersColumnDef<TGenerics extends AnyGenerics> = {
|
|
56
|
-
filterFn?:
|
|
56
|
+
filterFn?: FilterFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
57
57
|
enableAllFilters?: boolean
|
|
58
58
|
enableColumnFilter?: boolean
|
|
59
59
|
enableGlobalFilter?: boolean
|
|
@@ -63,7 +63,7 @@ export type FiltersColumnDef<TGenerics extends AnyGenerics> = {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export type FiltersColumn<TGenerics extends AnyGenerics> = {
|
|
66
|
-
filterFn:
|
|
66
|
+
filterFn: FilterFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
67
67
|
getCanColumnFilter: () => boolean
|
|
68
68
|
getCanGlobalFilter: () => boolean
|
|
69
69
|
getColumnFilterIndex: () => number
|
|
@@ -87,7 +87,7 @@ export type FiltersOptions<TGenerics extends AnyGenerics> = {
|
|
|
87
87
|
instance: TableInstance<TGenerics>
|
|
88
88
|
) => () => RowModel<TGenerics>
|
|
89
89
|
// Global
|
|
90
|
-
|
|
90
|
+
globalFilterFn?: FilterFnOption<TGenerics>
|
|
91
91
|
onGlobalFilterChange?: OnChangeFn<any>
|
|
92
92
|
autoResetGlobalFilter?: boolean
|
|
93
93
|
enableGlobalFilter?: boolean
|
|
@@ -161,7 +161,7 @@ export const Filters = {
|
|
|
161
161
|
autoResetColumnFilters: true,
|
|
162
162
|
filterFromLeafRows: true,
|
|
163
163
|
autoResetGlobalFilter: true,
|
|
164
|
-
|
|
164
|
+
globalFilterFn: 'auto',
|
|
165
165
|
getColumnCanGlobalFilterFn: column => {
|
|
166
166
|
const value = instance
|
|
167
167
|
.getCoreRowModel()
|
|
@@ -291,7 +291,7 @@ export const Filters = {
|
|
|
291
291
|
},
|
|
292
292
|
getColumnFilterFn: columnId => {
|
|
293
293
|
const column = instance.getColumn(columnId)
|
|
294
|
-
const
|
|
294
|
+
const userFilterFns = instance.options.filterFns
|
|
295
295
|
|
|
296
296
|
if (!column) {
|
|
297
297
|
throw new Error()
|
|
@@ -301,27 +301,27 @@ export const Filters = {
|
|
|
301
301
|
? column.filterFn
|
|
302
302
|
: column.filterFn === 'auto'
|
|
303
303
|
? instance.getColumnAutoFilterFn(columnId)
|
|
304
|
-
: (
|
|
304
|
+
: (userFilterFns as Record<string, any>)?.[
|
|
305
305
|
column.filterFn as string
|
|
306
306
|
] ??
|
|
307
307
|
(filterFns[
|
|
308
|
-
column.filterFn as
|
|
308
|
+
column.filterFn as BuiltInFilterFn
|
|
309
309
|
] as FilterFn<TGenerics>)
|
|
310
310
|
},
|
|
311
311
|
|
|
312
312
|
getGlobalFilterFn: () => {
|
|
313
|
-
const { filterFns:
|
|
313
|
+
const { filterFns: userFilterFns, globalFilterFn: globalFilterFn } =
|
|
314
314
|
instance.options
|
|
315
315
|
|
|
316
|
-
return isFunction(
|
|
317
|
-
?
|
|
318
|
-
:
|
|
316
|
+
return isFunction(globalFilterFn)
|
|
317
|
+
? globalFilterFn
|
|
318
|
+
: globalFilterFn === 'auto'
|
|
319
319
|
? instance.getGlobalAutoFilterFn()
|
|
320
|
-
: (
|
|
321
|
-
|
|
320
|
+
: (userFilterFns as Record<string, any>)?.[
|
|
321
|
+
globalFilterFn as string
|
|
322
322
|
] ??
|
|
323
323
|
(filterFns[
|
|
324
|
-
|
|
324
|
+
globalFilterFn as BuiltInFilterFn
|
|
325
325
|
] as FilterFn<TGenerics>)
|
|
326
326
|
},
|
|
327
327
|
|
package/src/features/Grouping.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RowModel } from '..'
|
|
2
|
-
import {
|
|
2
|
+
import { BuiltInAggregationFn, aggregationFns } from '../aggregationFns'
|
|
3
3
|
import {
|
|
4
4
|
Cell,
|
|
5
5
|
Column,
|
|
@@ -30,14 +30,14 @@ export type AggregationFn<TGenerics extends AnyGenerics> = (
|
|
|
30
30
|
getChildValues: () => TGenerics['Row'][]
|
|
31
31
|
) => any
|
|
32
32
|
|
|
33
|
-
export type
|
|
33
|
+
export type CustomAggregationFns<TGenerics extends AnyGenerics> = Record<
|
|
34
34
|
string,
|
|
35
35
|
AggregationFn<TGenerics>
|
|
36
36
|
>
|
|
37
37
|
|
|
38
|
-
export type
|
|
38
|
+
export type AggregationFnOption<TGenerics extends AnyGenerics> =
|
|
39
39
|
| 'auto'
|
|
40
|
-
|
|
|
40
|
+
| BuiltInAggregationFn
|
|
41
41
|
| keyof TGenerics['AggregationFns']
|
|
42
42
|
| AggregationFn<TGenerics>
|
|
43
43
|
|
|
@@ -46,7 +46,7 @@ export type GroupingTableState = {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export type GroupingColumnDef<TGenerics extends AnyGenerics> = {
|
|
49
|
-
aggregationFn?:
|
|
49
|
+
aggregationFn?: AggregationFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
50
50
|
aggregateValue?: (columnValue: unknown) => any
|
|
51
51
|
aggregatedCell?: Renderable<
|
|
52
52
|
TGenerics,
|
|
@@ -63,7 +63,7 @@ export type GroupingColumnDef<TGenerics extends AnyGenerics> = {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export type GroupingColumn<TGenerics extends AnyGenerics> = {
|
|
66
|
-
aggregationFn?:
|
|
66
|
+
aggregationFn?: AggregationFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
67
67
|
getCanGroup: () => boolean
|
|
68
68
|
getIsGrouped: () => boolean
|
|
69
69
|
getGroupedIndex: () => number
|
|
@@ -110,7 +110,7 @@ export type GroupingColumnMode = false | 'reorder' | 'remove'
|
|
|
110
110
|
|
|
111
111
|
export type ToggleGroupingProps = {
|
|
112
112
|
title?: string
|
|
113
|
-
onClick?: (event:
|
|
113
|
+
onClick?: (event: unknown) => void
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
export type GroupingInstance<TGenerics extends AnyGenerics> = {
|
|
@@ -221,7 +221,7 @@ export const Grouping = {
|
|
|
221
221
|
},
|
|
222
222
|
getColumnAggregationFn: columnId => {
|
|
223
223
|
const column = instance.getColumn(columnId)
|
|
224
|
-
const
|
|
224
|
+
const userAggregationFns = instance.options.aggregationFns
|
|
225
225
|
|
|
226
226
|
if (!column) {
|
|
227
227
|
throw new Error()
|
|
@@ -231,11 +231,11 @@ export const Grouping = {
|
|
|
231
231
|
? column.aggregationFn
|
|
232
232
|
: column.aggregationFn === 'auto'
|
|
233
233
|
? instance.getColumnAutoAggregationFn(columnId)
|
|
234
|
-
: (
|
|
234
|
+
: (userAggregationFns as Record<string, any>)?.[
|
|
235
235
|
column.aggregationFn as string
|
|
236
236
|
] ??
|
|
237
237
|
(aggregationFns[
|
|
238
|
-
column.aggregationFn as
|
|
238
|
+
column.aggregationFn as BuiltInAggregationFn
|
|
239
239
|
] as AggregationFn<TGenerics>)
|
|
240
240
|
},
|
|
241
241
|
|
|
@@ -290,7 +290,7 @@ export const Grouping = {
|
|
|
290
290
|
const initialProps: ToggleGroupingProps = {
|
|
291
291
|
title: canGroup ? 'Toggle Grouping' : undefined,
|
|
292
292
|
onClick: canGroup
|
|
293
|
-
? (e:
|
|
293
|
+
? (e: unknown) => {
|
|
294
294
|
column.toggleGrouping?.()
|
|
295
295
|
}
|
|
296
296
|
: undefined,
|
|
@@ -28,8 +28,8 @@ export type RowSelectionOptions<TGenerics extends AnyGenerics> = {
|
|
|
28
28
|
// | ((
|
|
29
29
|
// row: Row<TGenerics>
|
|
30
30
|
// ) => boolean)
|
|
31
|
-
// isAdditiveSelectEvent?: (e:
|
|
32
|
-
// isInclusiveSelectEvent?: (e:
|
|
31
|
+
// isAdditiveSelectEvent?: (e: unknown) => boolean
|
|
32
|
+
// isInclusiveSelectEvent?: (e: unknown) => boolean
|
|
33
33
|
// selectRowsFn?: (
|
|
34
34
|
// instance: TableInstance<
|
|
35
35
|
// TData,
|
|
@@ -43,7 +43,7 @@ export type RowSelectionOptions<TGenerics extends AnyGenerics> = {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
type ToggleRowSelectedProps = {
|
|
46
|
-
onChange?: (e:
|
|
46
|
+
onChange?: (e: unknown) => void
|
|
47
47
|
checked?: boolean
|
|
48
48
|
title?: string
|
|
49
49
|
indeterminate?: boolean
|
|
@@ -116,8 +116,8 @@ export const RowSelection = {
|
|
|
116
116
|
enableMultiRowSelection: true,
|
|
117
117
|
enableSubRowSelection: true,
|
|
118
118
|
// enableGroupingRowSelection: false,
|
|
119
|
-
// isAdditiveSelectEvent: (e:
|
|
120
|
-
// isInclusiveSelectEvent: (e:
|
|
119
|
+
// isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,
|
|
120
|
+
// isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
|
|
@@ -473,8 +473,10 @@ export const RowSelection = {
|
|
|
473
473
|
|
|
474
474
|
const initialProps: ToggleRowSelectedProps = {
|
|
475
475
|
onChange: canSelect
|
|
476
|
-
? (e:
|
|
477
|
-
row.toggleSelected(
|
|
476
|
+
? (e: unknown) => {
|
|
477
|
+
row.toggleSelected(
|
|
478
|
+
((e as MouseEvent).target as HTMLInputElement).checked
|
|
479
|
+
)
|
|
478
480
|
}
|
|
479
481
|
: undefined,
|
|
480
482
|
checked: isSelected,
|
|
@@ -504,9 +506,9 @@ export const RowSelection = {
|
|
|
504
506
|
const isAllRowsSelected = instance.getIsAllRowsSelected()
|
|
505
507
|
|
|
506
508
|
const initialProps: ToggleRowSelectedProps = {
|
|
507
|
-
onChange: (e:
|
|
509
|
+
onChange: (e: unknown) => {
|
|
508
510
|
instance.toggleAllRowsSelected(
|
|
509
|
-
(e.target as HTMLInputElement).checked
|
|
511
|
+
((e as MouseEvent).target as HTMLInputElement).checked
|
|
510
512
|
)
|
|
511
513
|
},
|
|
512
514
|
checked: isAllRowsSelected,
|
|
@@ -522,9 +524,9 @@ export const RowSelection = {
|
|
|
522
524
|
const isAllPageRowsSelected = instance.getIsAllPageRowsSelected()
|
|
523
525
|
|
|
524
526
|
const initialProps: ToggleRowSelectedProps = {
|
|
525
|
-
onChange: (e:
|
|
527
|
+
onChange: (e: unknown) => {
|
|
526
528
|
instance.toggleAllPageRowsSelected(
|
|
527
|
-
(e.target as HTMLInputElement).checked
|
|
529
|
+
((e as MouseEvent).target as HTMLInputElement).checked
|
|
528
530
|
)
|
|
529
531
|
},
|
|
530
532
|
checked: isAllPageRowsSelected,
|
package/src/features/Sorting.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { RowModel } from '..'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BuiltInSortingFn,
|
|
4
|
+
reSplitAlphaNumeric,
|
|
5
|
+
sortingFns,
|
|
6
|
+
} from '../sortingFns'
|
|
3
7
|
|
|
4
8
|
import {
|
|
5
9
|
Column,
|
|
@@ -36,7 +40,7 @@ export type SortingFn<TGenerics extends AnyGenerics> = {
|
|
|
36
40
|
(rowA: Row<TGenerics>, rowB: Row<TGenerics>, columnId: string): number
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
export type
|
|
43
|
+
export type CustomSortingFns<TGenerics extends AnyGenerics> = Record<
|
|
40
44
|
string,
|
|
41
45
|
SortingFn<TGenerics>
|
|
42
46
|
>
|
|
@@ -45,14 +49,14 @@ export type SortingTableState = {
|
|
|
45
49
|
sorting: SortingState
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
export type
|
|
52
|
+
export type SortingFnOption<TGenerics extends AnyGenerics> =
|
|
49
53
|
| 'auto'
|
|
50
|
-
|
|
|
54
|
+
| BuiltInSortingFn
|
|
51
55
|
| keyof TGenerics['SortingFns']
|
|
52
56
|
| SortingFn<TGenerics>
|
|
53
57
|
|
|
54
58
|
export type SortingColumnDef<TGenerics extends AnyGenerics> = {
|
|
55
|
-
sortingFn?:
|
|
59
|
+
sortingFn?: SortingFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
56
60
|
sortDescFirst?: boolean
|
|
57
61
|
enableSorting?: boolean
|
|
58
62
|
enableMultiSort?: boolean
|
|
@@ -62,7 +66,7 @@ export type SortingColumnDef<TGenerics extends AnyGenerics> = {
|
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
export type SortingColumn<TGenerics extends AnyGenerics> = {
|
|
65
|
-
sortingFn:
|
|
69
|
+
sortingFn: SortingFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
66
70
|
getCanSort: () => boolean
|
|
67
71
|
getCanMultiSort: () => boolean
|
|
68
72
|
getSortIndex: () => number
|
|
@@ -87,12 +91,12 @@ export type SortingOptions<TGenerics extends AnyGenerics> = {
|
|
|
87
91
|
instance: TableInstance<TGenerics>
|
|
88
92
|
) => () => RowModel<TGenerics>
|
|
89
93
|
maxMultiSortColCount?: number
|
|
90
|
-
isMultiSortEvent?: (e:
|
|
94
|
+
isMultiSortEvent?: (e: unknown) => boolean
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
export type ToggleSortingProps = {
|
|
94
98
|
title?: string
|
|
95
|
-
onClick?: (event:
|
|
99
|
+
onClick?: (event: unknown) => void
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
export type SortingInstance<TGenerics extends AnyGenerics> = {
|
|
@@ -145,8 +149,8 @@ export const Sorting = {
|
|
|
145
149
|
return {
|
|
146
150
|
onSortingChange: makeStateUpdater('sorting', instance),
|
|
147
151
|
autoResetSorting: true,
|
|
148
|
-
isMultiSortEvent: (e:
|
|
149
|
-
return e.shiftKey
|
|
152
|
+
isMultiSortEvent: (e: unknown) => {
|
|
153
|
+
return (e as MouseEvent).shiftKey
|
|
150
154
|
},
|
|
151
155
|
}
|
|
152
156
|
},
|
|
@@ -236,7 +240,7 @@ export const Sorting = {
|
|
|
236
240
|
},
|
|
237
241
|
getColumnSortingFn: columnId => {
|
|
238
242
|
const column = instance.getColumn(columnId)
|
|
239
|
-
const
|
|
243
|
+
const userSortingFn = instance.options.sortingFns
|
|
240
244
|
|
|
241
245
|
if (!column) {
|
|
242
246
|
throw new Error()
|
|
@@ -246,11 +250,11 @@ export const Sorting = {
|
|
|
246
250
|
? column.sortingFn
|
|
247
251
|
: column.sortingFn === 'auto'
|
|
248
252
|
? instance.getColumnAutoSortingFn(columnId)
|
|
249
|
-
: (
|
|
253
|
+
: (userSortingFn as Record<string, any>)?.[
|
|
250
254
|
column.sortingFn as string
|
|
251
255
|
] ??
|
|
252
256
|
(sortingFns[
|
|
253
|
-
column.sortingFn as
|
|
257
|
+
column.sortingFn as BuiltInSortingFn
|
|
254
258
|
] as SortingFn<TGenerics>)
|
|
255
259
|
},
|
|
256
260
|
|
|
@@ -428,7 +432,7 @@ export const Sorting = {
|
|
|
428
432
|
const initialProps: ToggleSortingProps = {
|
|
429
433
|
title: canSort ? 'Toggle Sorting' : undefined,
|
|
430
434
|
onClick: canSort
|
|
431
|
-
? (e:
|
|
435
|
+
? (e: unknown) => {
|
|
432
436
|
;(e as any).persist?.()
|
|
433
437
|
column.toggleSorting?.(
|
|
434
438
|
undefined,
|
|
@@ -102,8 +102,10 @@ export const Visibility = {
|
|
|
102
102
|
type: 'checkbox',
|
|
103
103
|
checked: column.getIsVisible?.(),
|
|
104
104
|
title: 'Toggle Column Visibility',
|
|
105
|
-
onChange: (e:
|
|
106
|
-
column.toggleVisibility?.(
|
|
105
|
+
onChange: (e: unknown) => {
|
|
106
|
+
column.toggleVisibility?.(
|
|
107
|
+
((e as MouseEvent).target as HTMLInputElement).checked
|
|
108
|
+
)
|
|
107
109
|
},
|
|
108
110
|
}
|
|
109
111
|
|
package/src/filterFns.ts
CHANGED
|
@@ -12,7 +12,7 @@ export const filterFns = {
|
|
|
12
12
|
betweenNumberRange,
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export type
|
|
15
|
+
export type BuiltInFilterFn = keyof typeof filterFns
|
|
16
16
|
|
|
17
17
|
function includesString<TGenerics extends AnyGenerics>(
|
|
18
18
|
rows: Row<TGenerics>[],
|
package/src/sortingFns.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyGenerics, Row } from './types'
|
|
2
2
|
|
|
3
3
|
export const reSplitAlphaNumeric = /([0-9]+)/gm
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ export const sortingFns = {
|
|
|
11
11
|
basic,
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export type
|
|
14
|
+
export type BuiltInSortingFn = keyof typeof sortingFns
|
|
15
15
|
|
|
16
16
|
function alphanumeric<TGenerics extends AnyGenerics>(
|
|
17
17
|
rowA: Row<TGenerics>,
|