@tanstack/table-core 8.0.0-alpha.44 → 8.0.0-alpha.47
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/{aggregationTypes.js → aggregationFns.js} +3 -3
- package/build/cjs/aggregationFns.js.map +1 -0
- package/build/cjs/core.js +2 -2
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +25 -18
- 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 +15 -15
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +8 -8
- 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 +10 -10
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/{filterTypes.js → filterFns.js} +3 -3
- package/build/cjs/filterFns.js.map +1 -0
- package/build/cjs/index.js +1 -1
- package/build/cjs/{sortTypes.js → sortingFns.js} +3 -3
- package/build/cjs/sortingFns.js.map +1 -0
- package/build/cjs/utils/getColumnFilteredRowModelSync.js +1 -1
- package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +1 -1
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils.js +7 -0
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +68 -54
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +314 -314
- package/build/types/{aggregationTypes.d.ts → aggregationFns.d.ts} +2 -2
- package/build/types/createTable.d.ts +28 -25
- package/build/types/features/Expanding.d.ts +1 -1
- package/build/types/features/Filters.d.ts +7 -7
- package/build/types/features/Grouping.d.ts +7 -7
- package/build/types/features/RowSelection.d.ts +1 -1
- package/build/types/features/Sorting.d.ts +8 -8
- package/build/types/{filterTypes.d.ts → filterFns.d.ts} +2 -2
- package/build/types/{sortTypes.d.ts → sortingFns.d.ts} +2 -2
- package/build/types/utils.d.ts +1 -0
- package/build/umd/index.development.js +68 -54
- 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/{aggregationTypes.ts → aggregationFns.ts} +2 -2
- package/src/core.ts +1 -2
- package/src/createTable.ts +75 -54
- package/src/features/ColumnSizing.ts +4 -4
- package/src/features/Expanding.ts +3 -3
- package/src/features/Filters.ts +34 -34
- package/src/features/Grouping.ts +22 -22
- package/src/features/RowSelection.ts +13 -11
- package/src/features/Sorting.ts +30 -26
- package/src/features/Visibility.ts +4 -2
- package/src/{filterTypes.ts → filterFns.ts} +2 -2
- package/src/{sortTypes.ts → sortingFns.ts} +3 -3
- package/src/utils/getColumnFilteredRowModelAsync.ts +1 -1
- package/src/utils/getColumnFilteredRowModelSync.ts +1 -1
- package/src/utils/getGroupedRowModel.ts +1 -1
- package/src/utils.ts +12 -1
- package/build/cjs/aggregationTypes.js.map +0 -1
- package/build/cjs/filterTypes.js.map +0 -1
- package/build/cjs/sortTypes.js.map +0 -1
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.47",
|
|
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",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const aggregationFns = {
|
|
2
2
|
sum,
|
|
3
3
|
min,
|
|
4
4
|
max,
|
|
@@ -10,7 +10,7 @@ export const aggregationTypes = {
|
|
|
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/core.ts
CHANGED
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
CellProps,
|
|
27
27
|
TableInstance,
|
|
28
28
|
RowValues,
|
|
29
|
-
PartialGenerics,
|
|
30
29
|
CoreCell,
|
|
31
30
|
Renderable,
|
|
32
31
|
UseRenderer,
|
|
@@ -46,7 +45,7 @@ import { RowSelection } from './features/RowSelection'
|
|
|
46
45
|
import { Sorting } from './features/Sorting'
|
|
47
46
|
import { Visibility } from './features/Visibility'
|
|
48
47
|
import { Headers } from './features/Headers'
|
|
49
|
-
import { mean } from './
|
|
48
|
+
import { mean } from './aggregationFns'
|
|
50
49
|
|
|
51
50
|
const features: TableFeature[] = [
|
|
52
51
|
Headers,
|
package/src/createTable.ts
CHANGED
|
@@ -1,38 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
AccessorFn,
|
|
7
|
-
PartialGenerics,
|
|
8
|
-
AnyRender,
|
|
9
|
-
AnyGenerics,
|
|
10
|
-
} from './types'
|
|
11
|
-
import { Overwrite, PartialKeys } from './utils'
|
|
1
|
+
import { CustomFilterFns, FilterFn } from './features/Filters'
|
|
2
|
+
import { AggregationFn, CustomAggregationFns } from './features/Grouping'
|
|
3
|
+
import { CustomSortingFns, SortingFn } from './features/Sorting'
|
|
4
|
+
import { ColumnDef, AccessorFn, AnyRender, AnyGenerics, Options } from './types'
|
|
5
|
+
import { IfDefined, Overwrite, PartialKeys } from './utils'
|
|
12
6
|
|
|
13
|
-
export type
|
|
14
|
-
TSubGenerics extends {
|
|
15
|
-
Row: any
|
|
16
|
-
ColumnMeta?: object
|
|
17
|
-
TableMeta?: object
|
|
18
|
-
}
|
|
19
|
-
>() => Table<Overwrite<TGenerics, TSubGenerics>>
|
|
7
|
+
export type TableFactory<TGenerics extends AnyGenerics> = () => Table<TGenerics>
|
|
20
8
|
|
|
21
|
-
export type
|
|
9
|
+
export type CreateTableOptions<
|
|
22
10
|
TRender extends AnyRender,
|
|
23
|
-
TFilterFns extends
|
|
24
|
-
TSortingFns extends
|
|
25
|
-
TAggregationFns extends
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
TFilterFns extends CustomFilterFns<any>,
|
|
12
|
+
TSortingFns extends CustomSortingFns<any>,
|
|
13
|
+
TAggregationFns extends CustomAggregationFns<any>,
|
|
14
|
+
TGenerics extends AnyGenerics
|
|
15
|
+
> = Partial<
|
|
16
|
+
{
|
|
17
|
+
render?: TRender
|
|
18
|
+
filterFns?: TFilterFns
|
|
19
|
+
sortingFns?: TSortingFns
|
|
20
|
+
aggregationFns?: TAggregationFns
|
|
21
|
+
} & Omit<Options<TGenerics>, 'filterFns' | 'sortingFns' | 'aggregationFns'>
|
|
22
|
+
>
|
|
32
23
|
|
|
33
24
|
export type Table<TGenerics extends AnyGenerics> = {
|
|
34
25
|
generics: TGenerics
|
|
35
|
-
|
|
26
|
+
options: Partial<Options<TGenerics>>
|
|
27
|
+
setRowType: <TRow extends object>() => Table<
|
|
28
|
+
Overwrite<TGenerics, { Row: TRow }>
|
|
29
|
+
>
|
|
30
|
+
setTableMetaType: <TTableMeta extends object>() => Table<
|
|
31
|
+
Overwrite<TGenerics, { TableMeta: TTableMeta }>
|
|
32
|
+
>
|
|
33
|
+
setColumnMetaType: <TColumnMeta extends object>() => Table<
|
|
34
|
+
Overwrite<TGenerics, { ColumnMeta: TColumnMeta }>
|
|
35
|
+
>
|
|
36
|
+
setOptions: <
|
|
37
|
+
TFilterFns extends Record<string, FilterFn<any>>,
|
|
38
|
+
TSortingFns extends Record<string, SortingFn<any>>,
|
|
39
|
+
TAggregationFns extends Record<string, AggregationFn<any>>
|
|
40
|
+
>(
|
|
41
|
+
options: CreateTableOptions<
|
|
42
|
+
any,
|
|
43
|
+
TFilterFns,
|
|
44
|
+
TSortingFns,
|
|
45
|
+
TAggregationFns,
|
|
46
|
+
TGenerics
|
|
47
|
+
>
|
|
48
|
+
) => Table<
|
|
49
|
+
Overwrite<
|
|
50
|
+
TGenerics,
|
|
51
|
+
{
|
|
52
|
+
FilterFns: IfDefined<TFilterFns, TGenerics['FilterFns']>
|
|
53
|
+
SortingFns: IfDefined<TSortingFns, TGenerics['SortingFns']>
|
|
54
|
+
AggregationFns: IfDefined<TAggregationFns, TGenerics['AggregationFns']>
|
|
55
|
+
}
|
|
56
|
+
>
|
|
57
|
+
>
|
|
36
58
|
createColumns: <TColumnDef extends ColumnDef<any>>(
|
|
37
59
|
columns: TColumnDef[]
|
|
38
60
|
) => TColumnDef[]
|
|
@@ -95,39 +117,36 @@ export type Table<TGenerics extends AnyGenerics> = {
|
|
|
95
117
|
) => ColumnDef<TGenerics>
|
|
96
118
|
}
|
|
97
119
|
|
|
98
|
-
type InitTable<TRender extends AnyRender> = {
|
|
99
|
-
createTableFactory: <TGenerics extends AnyGenerics>(
|
|
100
|
-
options: CreateTableFactoryOptions<TRender, any, any, any>
|
|
101
|
-
) => CreateTableFactory<Overwrite<TGenerics, { Render: TRender }>>
|
|
102
|
-
createTable: CreateTableFactory<
|
|
103
|
-
Overwrite<PartialGenerics, { Render: TRender }>
|
|
104
|
-
>
|
|
105
|
-
}
|
|
106
|
-
|
|
107
120
|
//
|
|
108
121
|
|
|
109
|
-
export function
|
|
122
|
+
export function createTableFactory<TRender extends AnyRender>(opts: {
|
|
110
123
|
render: TRender
|
|
111
|
-
}):
|
|
112
|
-
return
|
|
113
|
-
createTableFactory: factoryOptions => () =>
|
|
114
|
-
_createTable(undefined, undefined, { ...factoryOptions, ...opts }),
|
|
115
|
-
createTable: () => _createTable(undefined, undefined, opts),
|
|
116
|
-
}
|
|
124
|
+
}): () => Table<{ Render: TRender }> {
|
|
125
|
+
return () => createTable(undefined, undefined, opts)
|
|
117
126
|
}
|
|
118
127
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
// A lot of returns in here are `as any` for a reason. Unless you
|
|
129
|
+
// can find a better way to do this, then don't worry about them
|
|
130
|
+
function createTable<TGenerics extends AnyGenerics>(
|
|
131
|
+
_?: undefined,
|
|
132
|
+
__?: undefined,
|
|
133
|
+
options?: CreateTableOptions<any, any, any, any, TGenerics>
|
|
123
134
|
): Table<TGenerics> {
|
|
124
|
-
|
|
135
|
+
const table: Table<TGenerics> = {
|
|
125
136
|
generics: undefined!,
|
|
126
|
-
|
|
127
|
-
render: () => {
|
|
128
|
-
throw new Error()
|
|
129
|
-
},
|
|
137
|
+
options: options ?? {
|
|
138
|
+
render: (() => {
|
|
139
|
+
throw new Error('')
|
|
140
|
+
})(),
|
|
130
141
|
},
|
|
142
|
+
setRowType: () => table as any,
|
|
143
|
+
setTableMetaType: () => table as any,
|
|
144
|
+
setColumnMetaType: () => table as any,
|
|
145
|
+
setOptions: newOptions =>
|
|
146
|
+
createTable(_, __, {
|
|
147
|
+
...options,
|
|
148
|
+
...newOptions,
|
|
149
|
+
} as any),
|
|
131
150
|
createColumns: columns => columns,
|
|
132
151
|
createDisplayColumn: column => ({ ...column, columnDefType: 'display' }),
|
|
133
152
|
createGroup: column => ({ ...column, columnDefType: 'group' } as any),
|
|
@@ -156,4 +175,6 @@ function _createTable<TGenerics extends AnyGenerics>(
|
|
|
156
175
|
throw new Error('Invalid accessor')
|
|
157
176
|
},
|
|
158
177
|
}
|
|
178
|
+
|
|
179
|
+
return table
|
|
159
180
|
}
|
|
@@ -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
|
-
|
|
|
52
|
-
| TGenerics['FilterFns']
|
|
51
|
+
| BuiltInFilterFn
|
|
52
|
+
| keyof TGenerics['FilterFns']
|
|
53
53
|
| FilterFn<TGenerics>
|
|
54
54
|
|
|
55
55
|
export type FiltersColumnDef<TGenerics extends AnyGenerics> = {
|
|
56
|
-
|
|
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
|
-
|
|
66
|
+
filterFn: FilterFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
67
67
|
getCanColumnFilter: () => boolean
|
|
68
68
|
getCanGlobalFilter: () => boolean
|
|
69
69
|
getColumnFilterIndex: () => number
|
|
@@ -77,7 +77,7 @@ export type FiltersColumn<TGenerics extends AnyGenerics> = {
|
|
|
77
77
|
|
|
78
78
|
export type FiltersOptions<TGenerics extends AnyGenerics> = {
|
|
79
79
|
filterFromLeafRows?: boolean
|
|
80
|
-
|
|
80
|
+
filterFns?: TGenerics['FilterFns']
|
|
81
81
|
enableFilters?: boolean
|
|
82
82
|
// Column
|
|
83
83
|
onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>
|
|
@@ -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
|
|
@@ -139,7 +139,7 @@ export const Filters = {
|
|
|
139
139
|
TGenerics extends AnyGenerics
|
|
140
140
|
>(): FiltersColumnDef<TGenerics> => {
|
|
141
141
|
return {
|
|
142
|
-
|
|
142
|
+
filterFn: 'auto',
|
|
143
143
|
}
|
|
144
144
|
},
|
|
145
145
|
|
|
@@ -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()
|
|
@@ -217,7 +217,7 @@ export const Filters = {
|
|
|
217
217
|
)
|
|
218
218
|
|
|
219
219
|
return {
|
|
220
|
-
|
|
220
|
+
filterFn: column.filterFn,
|
|
221
221
|
getCanColumnFilter: () => instance.getColumnCanColumnFilter(column.id),
|
|
222
222
|
getCanGlobalFilter: () => instance.getColumnCanGlobalFilter(column.id),
|
|
223
223
|
getColumnFilterIndex: () => instance.getColumnFilterIndex(column.id),
|
|
@@ -269,59 +269,59 @@ export const Filters = {
|
|
|
269
269
|
const value = firstRow?.values[columnId]
|
|
270
270
|
|
|
271
271
|
if (typeof value === 'string') {
|
|
272
|
-
return
|
|
272
|
+
return filterFns.includesString
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
if (typeof value === 'number') {
|
|
276
|
-
return
|
|
276
|
+
return filterFns.betweenNumberRange
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
if (value !== null && typeof value === 'object') {
|
|
280
|
-
return
|
|
280
|
+
return filterFns.equals
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
if (Array.isArray(value)) {
|
|
284
|
-
return
|
|
284
|
+
return filterFns.arrIncludes
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
return
|
|
287
|
+
return filterFns.weakEquals
|
|
288
288
|
},
|
|
289
289
|
getGlobalAutoFilterFn: () => {
|
|
290
|
-
return
|
|
290
|
+
return filterFns.includesString
|
|
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()
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
return isFunction(column.
|
|
301
|
-
? column.
|
|
302
|
-
: column.
|
|
300
|
+
return isFunction(column.filterFn)
|
|
301
|
+
? column.filterFn
|
|
302
|
+
: column.filterFn === 'auto'
|
|
303
303
|
? instance.getColumnAutoFilterFn(columnId)
|
|
304
|
-
: (
|
|
305
|
-
column.
|
|
304
|
+
: (userFilterFns as Record<string, any>)?.[
|
|
305
|
+
column.filterFn as string
|
|
306
306
|
] ??
|
|
307
|
-
(
|
|
308
|
-
column.
|
|
307
|
+
(filterFns[
|
|
308
|
+
column.filterFn as BuiltInFilterFn
|
|
309
309
|
] as FilterFn<TGenerics>)
|
|
310
310
|
},
|
|
311
311
|
|
|
312
312
|
getGlobalFilterFn: () => {
|
|
313
|
-
const {
|
|
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
|
-
(
|
|
324
|
-
|
|
323
|
+
(filterFns[
|
|
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
|
-
|
|
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
|
-
|
|
66
|
+
aggregationFn?: AggregationFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
67
67
|
getCanGroup: () => boolean
|
|
68
68
|
getIsGrouped: () => boolean
|
|
69
69
|
getGroupedIndex: () => number
|
|
@@ -94,7 +94,7 @@ export type ColumnDefaultOptions = {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export type GroupingOptions<TGenerics extends AnyGenerics> = {
|
|
97
|
-
|
|
97
|
+
aggregationFns?: TGenerics['AggregationFns']
|
|
98
98
|
onGroupingChange?: OnChangeFn<GroupingState>
|
|
99
99
|
autoResetGrouping?: boolean
|
|
100
100
|
enableGrouping?: boolean
|
|
@@ -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> = {
|
|
@@ -144,7 +144,7 @@ export const Grouping = {
|
|
|
144
144
|
TGenerics extends AnyGenerics
|
|
145
145
|
>(): GroupingColumnDef<TGenerics> => {
|
|
146
146
|
return {
|
|
147
|
-
|
|
147
|
+
aggregationFn: 'auto',
|
|
148
148
|
}
|
|
149
149
|
},
|
|
150
150
|
|
|
@@ -169,7 +169,7 @@ export const Grouping = {
|
|
|
169
169
|
instance: TableInstance<TGenerics>
|
|
170
170
|
): GroupingColumn<TGenerics> => {
|
|
171
171
|
return {
|
|
172
|
-
|
|
172
|
+
aggregationFn: column.aggregationFn,
|
|
173
173
|
getCanGroup: () => instance.getColumnCanGroup(column.id),
|
|
174
174
|
getGroupedIndex: () => instance.getColumnGroupedIndex(column.id),
|
|
175
175
|
getIsGrouped: () => instance.getColumnIsGrouped(column.id),
|
|
@@ -210,32 +210,32 @@ export const Grouping = {
|
|
|
210
210
|
const value = firstRow?.values[columnId]
|
|
211
211
|
|
|
212
212
|
if (typeof value === 'number') {
|
|
213
|
-
return
|
|
213
|
+
return aggregationFns.sum
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
217
|
-
return
|
|
217
|
+
return aggregationFns.extent
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
return
|
|
220
|
+
return aggregationFns.count
|
|
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()
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
return isFunction(column.
|
|
231
|
-
? column.
|
|
232
|
-
: column.
|
|
230
|
+
return isFunction(column.aggregationFn)
|
|
231
|
+
? column.aggregationFn
|
|
232
|
+
: column.aggregationFn === 'auto'
|
|
233
233
|
? instance.getColumnAutoAggregationFn(columnId)
|
|
234
|
-
: (
|
|
235
|
-
column.
|
|
234
|
+
: (userAggregationFns as Record<string, any>)?.[
|
|
235
|
+
column.aggregationFn as string
|
|
236
236
|
] ??
|
|
237
|
-
(
|
|
238
|
-
column.
|
|
237
|
+
(aggregationFns[
|
|
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,
|