@tanstack/table-core 8.0.0-alpha.79 → 8.0.0-alpha.83
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/core.js.map +1 -1
- package/build/cjs/createTable.js +4 -2
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Cells.js +1 -1
- package/build/cjs/features/Cells.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +5 -5
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js +8 -6
- package/build/cjs/features/Columns.js.map +1 -1
- package/build/cjs/features/Filters.js +11 -6
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +5 -5
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +2 -2
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Pinning.js +14 -8
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/Rows.js +1 -1
- package/build/cjs/features/Rows.js.map +1 -1
- package/build/cjs/features/Sorting.js +9 -9
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +3 -3
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/index.js +8 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +1 -1
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getFacetedRowModel.js +1 -1
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
- package/build/cjs/utils/getFilteredRowModel.js +20 -9
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +2 -2
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +2 -2
- package/build/cjs/utils/getSortedRowModel.js.map +1 -1
- package/build/esm/index.js +90 -64
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +344 -326
- package/build/types/core.d.ts +4 -4
- package/build/types/createTable.d.ts +8 -5
- package/build/types/features/Columns.d.ts +2 -2
- package/build/types/features/Filters.d.ts +3 -2
- package/build/types/features/Grouping.d.ts +1 -1
- package/build/types/features/Pinning.d.ts +1 -1
- package/build/types/index.d.ts +3 -0
- package/build/types/types.d.ts +6 -3
- package/build/umd/index.development.js +94 -63
- 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/core.ts +6 -6
- package/src/createTable.ts +14 -7
- package/src/features/Cells.ts +2 -2
- package/src/features/ColumnSizing.ts +5 -5
- package/src/features/Columns.ts +12 -8
- package/src/features/Filters.ts +18 -6
- package/src/features/Grouping.ts +6 -5
- package/src/features/Headers.ts +4 -4
- package/src/features/Pinning.ts +10 -5
- package/src/features/Rows.ts +5 -1
- package/src/features/Sorting.ts +10 -10
- package/src/features/Visibility.ts +2 -2
- package/src/index.ts +3 -0
- package/src/types.ts +10 -5
- package/src/utils/filterRowsUtils.ts +1 -1
- package/src/utils/getFacetedRowModel.ts +1 -1
- package/src/utils/getFilteredRowModel.ts +24 -13
- package/src/utils/getGroupedRowModel.ts +3 -2
- package/src/utils/getSortedRowModel.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.83",
|
|
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/core.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { functionalUpdate, RequiredKeys } from './utils'
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
Updater,
|
|
5
|
-
|
|
5
|
+
TableOptionsResolved,
|
|
6
6
|
TableState,
|
|
7
7
|
TableInstance,
|
|
8
8
|
Renderable,
|
|
@@ -52,8 +52,8 @@ export type CoreInstance<TGenerics extends TableGenerics> = {
|
|
|
52
52
|
// generics: TGenerics
|
|
53
53
|
initialState: TableState
|
|
54
54
|
reset: () => void
|
|
55
|
-
options: RequiredKeys<
|
|
56
|
-
setOptions: (newOptions: Updater<
|
|
55
|
+
options: RequiredKeys<TableOptionsResolved<TGenerics>, 'state'>
|
|
56
|
+
setOptions: (newOptions: Updater<TableOptionsResolved<TGenerics>>) => void
|
|
57
57
|
getState: () => TableState
|
|
58
58
|
setState: (updater: Updater<TableState>) => void
|
|
59
59
|
_queue: (cb: () => void) => void
|
|
@@ -89,7 +89,7 @@ export type CoreInstance<TGenerics extends TableGenerics> = {
|
|
|
89
89
|
// }
|
|
90
90
|
|
|
91
91
|
export function createTableInstance<TGenerics extends TableGenerics>(
|
|
92
|
-
options:
|
|
92
|
+
options: TableOptionsResolved<TGenerics>
|
|
93
93
|
): TableInstance<TGenerics> {
|
|
94
94
|
if (options.debugAll || options.debugTable) {
|
|
95
95
|
console.info('Creating Table Instance...')
|
|
@@ -116,9 +116,9 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
116
116
|
|
|
117
117
|
const defaultOptions = instance._features.reduce((obj, feature) => {
|
|
118
118
|
return Object.assign(obj, feature.getDefaultOptions?.(instance))
|
|
119
|
-
}, {}) as
|
|
119
|
+
}, {}) as TableOptionsResolved<TGenerics>
|
|
120
120
|
|
|
121
|
-
const mergeOptions = (options:
|
|
121
|
+
const mergeOptions = (options: TableOptionsResolved<TGenerics>) => {
|
|
122
122
|
if (instance.options.mergeOptions) {
|
|
123
123
|
return instance.options.mergeOptions(defaultOptions, options)
|
|
124
124
|
}
|
package/src/createTable.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
AccessorFn,
|
|
7
7
|
AnyRender,
|
|
8
8
|
TableGenerics,
|
|
9
|
+
TableOptionsResolved,
|
|
9
10
|
TableOptions,
|
|
10
11
|
} from './types'
|
|
11
12
|
import { IfDefined, Overwrite } from './utils'
|
|
@@ -26,15 +27,15 @@ export type CreateTableOptions<
|
|
|
26
27
|
sortingFns?: TSortingFns
|
|
27
28
|
aggregationFns?: TAggregationFns
|
|
28
29
|
} & Omit<
|
|
29
|
-
|
|
30
|
+
TableOptionsResolved<TGenerics>,
|
|
30
31
|
'filterFns' | 'sortingFns' | 'aggregationFns'
|
|
31
32
|
>
|
|
32
33
|
>
|
|
33
34
|
|
|
34
35
|
export type Table<TGenerics extends TableGenerics> = {
|
|
35
36
|
generics: TGenerics
|
|
36
|
-
options: Partial<
|
|
37
|
-
setGenerics: <T extends TableGenerics>() => Table<T>
|
|
37
|
+
options: Partial<TableOptionsResolved<TGenerics>>
|
|
38
|
+
// setGenerics: <T extends TableGenerics>() => Table<T>
|
|
38
39
|
setRowType: <TRow>() => Table<Overwrite<TGenerics, { Row: TRow }>>
|
|
39
40
|
setTableMetaType: <TTableMeta>() => Table<
|
|
40
41
|
Overwrite<TGenerics, { TableMeta: TTableMeta }>
|
|
@@ -42,10 +43,13 @@ export type Table<TGenerics extends TableGenerics> = {
|
|
|
42
43
|
setColumnMetaType: <TColumnMeta>() => Table<
|
|
43
44
|
Overwrite<TGenerics, { ColumnMeta: TColumnMeta }>
|
|
44
45
|
>
|
|
46
|
+
setFilterMetaType: <TFilterMeta>() => Table<
|
|
47
|
+
Overwrite<TGenerics, { FilterMeta: TFilterMeta }>
|
|
48
|
+
>
|
|
45
49
|
setOptions: <
|
|
46
|
-
TFilterFns extends Record<string, FilterFn<
|
|
47
|
-
TSortingFns extends Record<string, SortingFn<
|
|
48
|
-
TAggregationFns extends Record<string, AggregationFn<
|
|
50
|
+
TFilterFns extends Record<string, FilterFn<TGenerics>>,
|
|
51
|
+
TSortingFns extends Record<string, SortingFn<TGenerics>>,
|
|
52
|
+
TAggregationFns extends Record<string, AggregationFn<TGenerics>>
|
|
49
53
|
>(
|
|
50
54
|
options: CreateTableOptions<
|
|
51
55
|
any,
|
|
@@ -116,6 +120,7 @@ export type Table<TGenerics extends TableGenerics> = {
|
|
|
116
120
|
}
|
|
117
121
|
>
|
|
118
122
|
) => ColumnDef<TGenerics>
|
|
123
|
+
createOptions: (options: TableOptions<TGenerics>) => TableOptions<TGenerics>
|
|
119
124
|
}
|
|
120
125
|
|
|
121
126
|
//
|
|
@@ -140,10 +145,11 @@ function createTable<TGenerics extends TableGenerics>(
|
|
|
140
145
|
throw new Error('')
|
|
141
146
|
})(),
|
|
142
147
|
},
|
|
143
|
-
setGenerics: () => table as any,
|
|
148
|
+
// setGenerics: () => table as any,
|
|
144
149
|
setRowType: () => table as any,
|
|
145
150
|
setTableMetaType: () => table as any,
|
|
146
151
|
setColumnMetaType: () => table as any,
|
|
152
|
+
setFilterMetaType: () => table as any,
|
|
147
153
|
setOptions: newOptions =>
|
|
148
154
|
createTable(_, __, {
|
|
149
155
|
...options,
|
|
@@ -175,6 +181,7 @@ function createTable<TGenerics extends TableGenerics>(
|
|
|
175
181
|
|
|
176
182
|
throw new Error('Invalid accessor')
|
|
177
183
|
},
|
|
184
|
+
createOptions: options => options,
|
|
178
185
|
}
|
|
179
186
|
|
|
180
187
|
return table
|
package/src/features/Cells.ts
CHANGED
|
@@ -93,7 +93,7 @@ const getDefaultColumnSizingInfoState = (): ColumnSizingInfoState => ({
|
|
|
93
93
|
})
|
|
94
94
|
|
|
95
95
|
export const ColumnSizing: TableFeature = {
|
|
96
|
-
|
|
96
|
+
getDefaultColumnDef: (): ColumnSizingColumnDef => {
|
|
97
97
|
return defaultColumnSizing
|
|
98
98
|
},
|
|
99
99
|
getInitialState: (state): ColumnSizingTableState => {
|
|
@@ -124,10 +124,10 @@ export const ColumnSizing: TableFeature = {
|
|
|
124
124
|
|
|
125
125
|
return Math.min(
|
|
126
126
|
Math.max(
|
|
127
|
-
column.minSize ?? defaultColumnSizing.minSize,
|
|
128
|
-
columnSize ?? column.size ?? defaultColumnSizing.size
|
|
127
|
+
column.columnDef.minSize ?? defaultColumnSizing.minSize,
|
|
128
|
+
columnSize ?? column.columnDef.size ?? defaultColumnSizing.size
|
|
129
129
|
),
|
|
130
|
-
column.maxSize ?? defaultColumnSizing.maxSize
|
|
130
|
+
column.columnDef.maxSize ?? defaultColumnSizing.maxSize
|
|
131
131
|
)
|
|
132
132
|
},
|
|
133
133
|
getStart: position => {
|
|
@@ -156,7 +156,7 @@ export const ColumnSizing: TableFeature = {
|
|
|
156
156
|
},
|
|
157
157
|
getCanResize: () => {
|
|
158
158
|
return (
|
|
159
|
-
(column.enableResizing ?? true) &&
|
|
159
|
+
(column.columnDef.enableResizing ?? true) &&
|
|
160
160
|
(instance.options.enableColumnResizing ?? true)
|
|
161
161
|
)
|
|
162
162
|
},
|
package/src/features/Columns.ts
CHANGED
|
@@ -61,11 +61,11 @@ export type CoreColumn<TGenerics extends TableGenerics> = {
|
|
|
61
61
|
|
|
62
62
|
export type ColumnsOptions<TGenerics extends TableGenerics> = {
|
|
63
63
|
columns: ColumnDef<TGenerics>[]
|
|
64
|
-
|
|
64
|
+
defaultColumnDef?: Partial<ColumnDef<TGenerics>>
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export type ColumnsInstance<TGenerics extends TableGenerics> = {
|
|
68
|
-
|
|
68
|
+
getDefaultColumnDef: () => Partial<ColumnDef<TGenerics>>
|
|
69
69
|
getColumnDefs: () => ColumnDef<TGenerics>[]
|
|
70
70
|
createColumn: (
|
|
71
71
|
columnDef: ColumnDef<TGenerics>,
|
|
@@ -86,8 +86,8 @@ export const Columns = {
|
|
|
86
86
|
instance: TableInstance<TGenerics>
|
|
87
87
|
): ColumnsInstance<TGenerics> => {
|
|
88
88
|
return {
|
|
89
|
-
|
|
90
|
-
() => [instance.options.
|
|
89
|
+
getDefaultColumnDef: memo(
|
|
90
|
+
() => [instance.options.defaultColumnDef],
|
|
91
91
|
defaultColumn => {
|
|
92
92
|
defaultColumn = (defaultColumn ?? {}) as Partial<ColumnDef<TGenerics>>
|
|
93
93
|
|
|
@@ -96,7 +96,7 @@ export const Columns = {
|
|
|
96
96
|
footer: props => props.header.column.id,
|
|
97
97
|
cell: props => props.getValue().toString?.() ?? null,
|
|
98
98
|
...instance._features.reduce((obj, feature) => {
|
|
99
|
-
return Object.assign(obj, feature.
|
|
99
|
+
return Object.assign(obj, feature.getDefaultColumnDef?.())
|
|
100
100
|
}, {}),
|
|
101
101
|
...defaultColumn,
|
|
102
102
|
} as Partial<ColumnDef<TGenerics>>
|
|
@@ -104,7 +104,7 @@ export const Columns = {
|
|
|
104
104
|
{
|
|
105
105
|
debug: () =>
|
|
106
106
|
instance.options.debugAll ?? instance.options.debugColumns,
|
|
107
|
-
key: process.env.NODE_ENV === 'development' && '
|
|
107
|
+
key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef',
|
|
108
108
|
}
|
|
109
109
|
),
|
|
110
110
|
|
|
@@ -115,7 +115,12 @@ export const Columns = {
|
|
|
115
115
|
depth: number,
|
|
116
116
|
parent
|
|
117
117
|
) => {
|
|
118
|
-
const
|
|
118
|
+
const defaultColumnDef = instance.getDefaultColumnDef()
|
|
119
|
+
|
|
120
|
+
columnDef = {
|
|
121
|
+
...defaultColumnDef,
|
|
122
|
+
...columnDef,
|
|
123
|
+
}
|
|
119
124
|
|
|
120
125
|
let id =
|
|
121
126
|
columnDef.id ??
|
|
@@ -143,7 +148,6 @@ export const Columns = {
|
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
let column: CoreColumn<TGenerics> = {
|
|
146
|
-
...defaultColumn,
|
|
147
151
|
...columnDef,
|
|
148
152
|
id: `${id}`,
|
|
149
153
|
accessorFn,
|
package/src/features/Filters.ts
CHANGED
|
@@ -38,7 +38,13 @@ export type ResolvedColumnFilter<TGenerics extends TableGenerics> = {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export type FilterFn<TGenerics extends TableGenerics> = {
|
|
41
|
-
(
|
|
41
|
+
(
|
|
42
|
+
row: Row<TGenerics>,
|
|
43
|
+
columnId: string,
|
|
44
|
+
filterValue: any,
|
|
45
|
+
addMeta: (meta: TGenerics['FilterMeta']) => void
|
|
46
|
+
): boolean
|
|
47
|
+
|
|
42
48
|
resolveFilterValue?: TransformFilterValueFn<TGenerics>
|
|
43
49
|
autoRemove?: ColumnFilterAutoRemoveTestFn<TGenerics>
|
|
44
50
|
}
|
|
@@ -90,7 +96,8 @@ export type FiltersColumn<TGenerics extends TableGenerics> = {
|
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
export type FiltersRow<TGenerics extends TableGenerics> = {
|
|
93
|
-
|
|
99
|
+
columnFilters: Record<string, boolean>
|
|
100
|
+
columnFiltersMeta: Record<string, TGenerics['FilterMeta']>
|
|
94
101
|
subRowsByFacetId: Record<string, Row<TGenerics>[]>
|
|
95
102
|
}
|
|
96
103
|
|
|
@@ -154,7 +161,7 @@ export type FiltersInstance<TGenerics extends TableGenerics> = {
|
|
|
154
161
|
//
|
|
155
162
|
|
|
156
163
|
export const Filters: TableFeature = {
|
|
157
|
-
|
|
164
|
+
getDefaultColumnDef: <
|
|
158
165
|
TGenerics extends TableGenerics
|
|
159
166
|
>(): FiltersColumnDef<TGenerics> => {
|
|
160
167
|
return {
|
|
@@ -210,6 +217,10 @@ export const Filters: TableFeature = {
|
|
|
210
217
|
return filterFns.inNumberRange
|
|
211
218
|
}
|
|
212
219
|
|
|
220
|
+
if (typeof value === 'boolean') {
|
|
221
|
+
return filterFns.equals
|
|
222
|
+
}
|
|
223
|
+
|
|
213
224
|
if (value !== null && typeof value === 'object') {
|
|
214
225
|
return filterFns.equals
|
|
215
226
|
}
|
|
@@ -236,7 +247,7 @@ export const Filters: TableFeature = {
|
|
|
236
247
|
},
|
|
237
248
|
getCanFilter: () => {
|
|
238
249
|
return (
|
|
239
|
-
(column.enableColumnFilter ?? true) &&
|
|
250
|
+
(column.columnDef.enableColumnFilter ?? true) &&
|
|
240
251
|
(instance.options.enableColumnFilters ?? true) &&
|
|
241
252
|
(instance.options.enableFilters ?? true) &&
|
|
242
253
|
!!column.accessorFn
|
|
@@ -245,7 +256,7 @@ export const Filters: TableFeature = {
|
|
|
245
256
|
|
|
246
257
|
getCanGlobalFilter: () => {
|
|
247
258
|
return (
|
|
248
|
-
(column.enableGlobalFilter ?? true) &&
|
|
259
|
+
(column.columnDef.enableGlobalFilter ?? true) &&
|
|
249
260
|
(instance.options.enableGlobalFilter ?? true) &&
|
|
250
261
|
(instance.options.enableFilters ?? true) &&
|
|
251
262
|
(instance.options.getColumnCanGlobalFilter?.(column) ?? true) &&
|
|
@@ -343,7 +354,8 @@ export const Filters: TableFeature = {
|
|
|
343
354
|
instance: TableInstance<TGenerics>
|
|
344
355
|
): FiltersRow<TGenerics> => {
|
|
345
356
|
return {
|
|
346
|
-
|
|
357
|
+
columnFilters: {},
|
|
358
|
+
columnFiltersMeta: {},
|
|
347
359
|
subRowsByFacetId: {},
|
|
348
360
|
}
|
|
349
361
|
},
|
package/src/features/Grouping.ts
CHANGED
|
@@ -16,8 +16,8 @@ import { isFunction, makeStateUpdater, Overwrite } from '../utils'
|
|
|
16
16
|
export type GroupingState = string[]
|
|
17
17
|
|
|
18
18
|
export type AggregationFn<TGenerics extends TableGenerics> = (
|
|
19
|
-
getLeafValues: () => TGenerics['
|
|
20
|
-
getChildValues: () => TGenerics['
|
|
19
|
+
getLeafValues: () => TGenerics['Value'][],
|
|
20
|
+
getChildValues: () => TGenerics['Value'][]
|
|
21
21
|
) => any
|
|
22
22
|
|
|
23
23
|
export type CustomAggregationFns<TGenerics extends TableGenerics> = Record<
|
|
@@ -108,7 +108,7 @@ export type GroupingInstance<TGenerics extends TableGenerics> = {
|
|
|
108
108
|
//
|
|
109
109
|
|
|
110
110
|
export const Grouping: TableFeature = {
|
|
111
|
-
|
|
111
|
+
getDefaultColumnDef: <
|
|
112
112
|
TGenerics extends TableGenerics
|
|
113
113
|
>(): GroupingColumnDef<TGenerics> => {
|
|
114
114
|
return {
|
|
@@ -150,7 +150,7 @@ export const Grouping: TableFeature = {
|
|
|
150
150
|
|
|
151
151
|
getCanGroup: () => {
|
|
152
152
|
return (
|
|
153
|
-
column.enableGrouping ??
|
|
153
|
+
column.columnDef.enableGrouping ??
|
|
154
154
|
true ??
|
|
155
155
|
instance.options.enableGrouping ??
|
|
156
156
|
true ??
|
|
@@ -264,7 +264,8 @@ export const Grouping: TableFeature = {
|
|
|
264
264
|
!cell.getIsPlaceholder() &&
|
|
265
265
|
row.subRows?.length > 1,
|
|
266
266
|
renderAggregatedCell: () => {
|
|
267
|
-
const template =
|
|
267
|
+
const template =
|
|
268
|
+
column.columnDef.aggregatedCell ?? column.columnDef.cell
|
|
268
269
|
|
|
269
270
|
return template
|
|
270
271
|
? instance._render(template, {
|
package/src/features/Headers.ts
CHANGED
|
@@ -87,16 +87,16 @@ export const Headers = {
|
|
|
87
87
|
return leafHeaders as Header<TGenerics>[]
|
|
88
88
|
},
|
|
89
89
|
renderHeader: () =>
|
|
90
|
-
column.header
|
|
91
|
-
? instance._render(column.header, {
|
|
90
|
+
column.columnDef.header
|
|
91
|
+
? instance._render(column.columnDef.header, {
|
|
92
92
|
instance,
|
|
93
93
|
header: header as Header<TGenerics>,
|
|
94
94
|
column,
|
|
95
95
|
})
|
|
96
96
|
: null,
|
|
97
97
|
renderFooter: () =>
|
|
98
|
-
column.footer
|
|
99
|
-
? instance._render(column.footer, {
|
|
98
|
+
column.columnDef.footer
|
|
99
|
+
? instance._render(column.columnDef.footer, {
|
|
100
100
|
instance,
|
|
101
101
|
header: header as Header<TGenerics>,
|
|
102
102
|
column,
|
package/src/features/Pinning.ts
CHANGED
|
@@ -50,7 +50,7 @@ export type ColumnPinningRow<TGenerics extends TableGenerics> = {
|
|
|
50
50
|
export type ColumnPinningInstance<TGenerics extends TableGenerics> = {
|
|
51
51
|
setColumnPinning: (updater: Updater<ColumnPinningState>) => void
|
|
52
52
|
resetColumnPinning: (defaultState?: boolean) => void
|
|
53
|
-
getIsSomeColumnsPinned: () => boolean
|
|
53
|
+
getIsSomeColumnsPinned: (position?: ColumnPinningPosition) => boolean
|
|
54
54
|
getLeftLeafColumns: () => Column<TGenerics>[]
|
|
55
55
|
getRightLeafColumns: () => Column<TGenerics>[]
|
|
56
56
|
getCenterLeafColumns: () => Column<TGenerics>[]
|
|
@@ -123,7 +123,7 @@ export const Pinning: TableFeature = {
|
|
|
123
123
|
|
|
124
124
|
return leafColumns.some(
|
|
125
125
|
d =>
|
|
126
|
-
(d.enablePinning ?? true) &&
|
|
126
|
+
(d.columnDef.enablePinning ?? true) &&
|
|
127
127
|
(instance.options.enablePinning ?? true)
|
|
128
128
|
)
|
|
129
129
|
},
|
|
@@ -229,10 +229,15 @@ export const Pinning: TableFeature = {
|
|
|
229
229
|
: instance.initialState?.columnPinning ?? getDefaultPinningState()
|
|
230
230
|
),
|
|
231
231
|
|
|
232
|
-
getIsSomeColumnsPinned:
|
|
233
|
-
const
|
|
232
|
+
getIsSomeColumnsPinned: position => {
|
|
233
|
+
const pinningState = instance.getState().columnPinning
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
if (!position) {
|
|
236
|
+
return Boolean(
|
|
237
|
+
pinningState.left?.length || pinningState.right?.length
|
|
238
|
+
)
|
|
239
|
+
}
|
|
240
|
+
return Boolean(pinningState[position]?.length)
|
|
236
241
|
},
|
|
237
242
|
|
|
238
243
|
getLeftLeafColumns: memo(
|
package/src/features/Rows.ts
CHANGED
|
@@ -85,14 +85,18 @@ export const Rows = {
|
|
|
85
85
|
if (row.valuesCache.hasOwnProperty(columnId)) {
|
|
86
86
|
return row.valuesCache[columnId]
|
|
87
87
|
}
|
|
88
|
+
|
|
88
89
|
const column = instance.getColumn(columnId)
|
|
90
|
+
|
|
89
91
|
if (!column.accessorFn) {
|
|
90
|
-
|
|
92
|
+
return undefined
|
|
91
93
|
}
|
|
94
|
+
|
|
92
95
|
row.valuesCache[columnId] = column.accessorFn(
|
|
93
96
|
row.original,
|
|
94
97
|
rowIndex
|
|
95
98
|
)
|
|
99
|
+
|
|
96
100
|
return row.valuesCache[columnId]
|
|
97
101
|
},
|
|
98
102
|
subRows: subRows ?? [],
|
package/src/features/Sorting.ts
CHANGED
|
@@ -101,7 +101,7 @@ export const Sorting: TableFeature = {
|
|
|
101
101
|
}
|
|
102
102
|
},
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
getDefaultColumnDef: <
|
|
105
105
|
TGenerics extends TableGenerics
|
|
106
106
|
>(): SortingColumnDef<TGenerics> => {
|
|
107
107
|
return {
|
|
@@ -126,7 +126,7 @@ export const Sorting: TableFeature = {
|
|
|
126
126
|
): SortingColumn<TGenerics> => {
|
|
127
127
|
return {
|
|
128
128
|
getAutoSortingFn: () => {
|
|
129
|
-
const firstRows = instance.getFilteredRowModel().flatRows.slice(
|
|
129
|
+
const firstRows = instance.getFilteredRowModel().flatRows.slice(10)
|
|
130
130
|
|
|
131
131
|
let isString = false
|
|
132
132
|
|
|
@@ -170,15 +170,15 @@ export const Sorting: TableFeature = {
|
|
|
170
170
|
throw new Error()
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
return isFunction(column.sortingFn)
|
|
174
|
-
? column.sortingFn
|
|
175
|
-
: column.sortingFn === 'auto'
|
|
173
|
+
return isFunction(column.columnDef.sortingFn)
|
|
174
|
+
? column.columnDef.sortingFn
|
|
175
|
+
: column.columnDef.sortingFn === 'auto'
|
|
176
176
|
? column.getAutoSortingFn()
|
|
177
177
|
: (userSortingFn as Record<string, any>)?.[
|
|
178
|
-
column.sortingFn as string
|
|
178
|
+
column.columnDef.sortingFn as string
|
|
179
179
|
] ??
|
|
180
180
|
(sortingFns[
|
|
181
|
-
column.sortingFn as BuiltInSortingFn
|
|
181
|
+
column.columnDef.sortingFn as BuiltInSortingFn
|
|
182
182
|
] as SortingFn<TGenerics>)
|
|
183
183
|
},
|
|
184
184
|
toggleSorting: (desc, multi) => {
|
|
@@ -220,7 +220,7 @@ export const Sorting: TableFeature = {
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
const sortDescFirst =
|
|
223
|
-
column.sortDescFirst ??
|
|
223
|
+
column.columnDef.sortDescFirst ??
|
|
224
224
|
instance.options.sortDescFirst ??
|
|
225
225
|
column.getAutoSortDir() === 'desc'
|
|
226
226
|
|
|
@@ -280,7 +280,7 @@ export const Sorting: TableFeature = {
|
|
|
280
280
|
|
|
281
281
|
getCanSort: () => {
|
|
282
282
|
return (
|
|
283
|
-
(column.enableSorting ?? true) &&
|
|
283
|
+
(column.columnDef.enableSorting ?? true) &&
|
|
284
284
|
(instance.options.enableSorting ?? true) &&
|
|
285
285
|
!!column.accessorFn
|
|
286
286
|
)
|
|
@@ -288,7 +288,7 @@ export const Sorting: TableFeature = {
|
|
|
288
288
|
|
|
289
289
|
getCanMultiSort: () => {
|
|
290
290
|
return (
|
|
291
|
-
column.enableMultiSort ??
|
|
291
|
+
column.columnDef.enableMultiSort ??
|
|
292
292
|
instance.options.enableMultiSort ??
|
|
293
293
|
!!column.accessorFn
|
|
294
294
|
)
|
|
@@ -76,7 +76,7 @@ export const Visibility: TableFeature = {
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
getDefaultColumnDef: () => {
|
|
80
80
|
return {
|
|
81
81
|
defaultIsVisible: true,
|
|
82
82
|
}
|
|
@@ -101,7 +101,7 @@ export const Visibility: TableFeature = {
|
|
|
101
101
|
|
|
102
102
|
getCanHide: () => {
|
|
103
103
|
return (
|
|
104
|
-
(column.enableHiding ?? true) &&
|
|
104
|
+
(column.columnDef.enableHiding ?? true) &&
|
|
105
105
|
(instance.options.enableHiding ?? true)
|
|
106
106
|
)
|
|
107
107
|
},
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,9 @@ export * from './features/RowSelection'
|
|
|
14
14
|
export * from './features/Sorting'
|
|
15
15
|
export * from './features/Visibility'
|
|
16
16
|
export * from './features/Expanding'
|
|
17
|
+
export * from './filterFns'
|
|
18
|
+
export * from './sortingFns'
|
|
19
|
+
export * from './aggregationFns'
|
|
17
20
|
export * from './utils'
|
|
18
21
|
export * from './utils/getCoreRowModel'
|
|
19
22
|
export * from './utils/getFilteredRowModel'
|
package/src/types.ts
CHANGED
|
@@ -53,7 +53,7 @@ import {
|
|
|
53
53
|
ExpandedTableState,
|
|
54
54
|
ExpandedRow,
|
|
55
55
|
} from './features/Expanding'
|
|
56
|
-
import { Overwrite } from './utils'
|
|
56
|
+
import { Overwrite, PartialKeys } from './utils'
|
|
57
57
|
import {
|
|
58
58
|
ColumnSizingColumn,
|
|
59
59
|
ColumnSizingColumnDef,
|
|
@@ -91,6 +91,7 @@ export type TableGenerics = {
|
|
|
91
91
|
Rendered?: any
|
|
92
92
|
ColumnMeta?: any
|
|
93
93
|
TableMeta?: any
|
|
94
|
+
FilterMeta?: any
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
export type AnyRender = (Comp: any, props: any) => any
|
|
@@ -99,7 +100,7 @@ export type TableFeature = {
|
|
|
99
100
|
getDefaultOptions?: (instance: any) => any
|
|
100
101
|
getInitialState?: (initialState?: InitialTableState) => any
|
|
101
102
|
createInstance?: (instance: any) => any
|
|
102
|
-
|
|
103
|
+
getDefaultColumnDef?: () => any
|
|
103
104
|
createColumn?: (column: any, instance: any) => any
|
|
104
105
|
createHeader?: (column: any, instance: any) => any
|
|
105
106
|
createCell?: (cell: any, column: any, row: any, instance: any) => any
|
|
@@ -123,7 +124,7 @@ export type TableInstance<TGenerics extends TableGenerics> =
|
|
|
123
124
|
PaginationInstance<TGenerics> &
|
|
124
125
|
RowSelectionInstance<TGenerics>
|
|
125
126
|
|
|
126
|
-
export type
|
|
127
|
+
export type TableOptionsResolved<TGenerics extends TableGenerics> =
|
|
127
128
|
CoreOptions<TGenerics> &
|
|
128
129
|
ColumnsOptions<TGenerics> &
|
|
129
130
|
RowsOptions<TGenerics> &
|
|
@@ -138,6 +139,11 @@ export type TableOptions<TGenerics extends TableGenerics> =
|
|
|
138
139
|
PaginationOptions<TGenerics> &
|
|
139
140
|
RowSelectionOptions<TGenerics>
|
|
140
141
|
|
|
142
|
+
export type TableOptions<TGenerics extends TableGenerics> = Omit<
|
|
143
|
+
PartialKeys<TableOptionsResolved<TGenerics>, 'state' | 'onStateChange'>,
|
|
144
|
+
'render'
|
|
145
|
+
>
|
|
146
|
+
|
|
141
147
|
export type TableState = CoreTableState &
|
|
142
148
|
VisibilityTableState &
|
|
143
149
|
ColumnOrderTableState &
|
|
@@ -198,8 +204,7 @@ export type ColumnDef<TGenerics extends TableGenerics> =
|
|
|
198
204
|
GroupingColumnDef<TGenerics> &
|
|
199
205
|
ColumnSizingColumnDef
|
|
200
206
|
|
|
201
|
-
export type Column<TGenerics extends TableGenerics> =
|
|
202
|
-
CoreColumn<TGenerics> &
|
|
207
|
+
export type Column<TGenerics extends TableGenerics> = CoreColumn<TGenerics> &
|
|
203
208
|
ColumnVisibilityColumn &
|
|
204
209
|
ColumnPinningColumn &
|
|
205
210
|
FiltersColumn<TGenerics> &
|
|
@@ -32,7 +32,7 @@ export function filterRowModelFromLeafs<TGenerics extends TableGenerics>(
|
|
|
32
32
|
|
|
33
33
|
if (row.subRows?.length) {
|
|
34
34
|
newRow = instance.createRow(row.id, row.original, row.index, row.depth)
|
|
35
|
-
newRow.
|
|
35
|
+
newRow.columnFilters = row.columnFilters
|
|
36
36
|
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
37
37
|
if (!newRow.subRows.length) {
|
|
38
38
|
continue
|
|
@@ -30,7 +30,7 @@ export function getFacetedRowModel<TGenerics extends TableGenerics>(): (
|
|
|
30
30
|
const filterRowsImpl = (row: Row<TGenerics>) => {
|
|
31
31
|
// Horizontally filter rows through each column
|
|
32
32
|
for (let i = 0; i < filterableIds.length; i++) {
|
|
33
|
-
if (row.
|
|
33
|
+
if (row.columnFilters[filterableIds[i]!] === false) {
|
|
34
34
|
return false
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -18,6 +18,10 @@ export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
|
|
|
18
18
|
!rowModel.rows.length ||
|
|
19
19
|
(!columnFilters?.length && !globalFilter)
|
|
20
20
|
) {
|
|
21
|
+
for (let i = 0; i < rowModel.flatRows.length; i++) {
|
|
22
|
+
rowModel.flatRows[i]!.columnFilters = {}
|
|
23
|
+
rowModel.flatRows[i]!.columnFiltersMeta = {}
|
|
24
|
+
}
|
|
21
25
|
return rowModel
|
|
22
26
|
}
|
|
23
27
|
|
|
@@ -86,40 +90,47 @@ export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
|
|
|
86
90
|
for (let j = 0; j < rowModel.flatRows.length; j++) {
|
|
87
91
|
const row = rowModel.flatRows[j]!
|
|
88
92
|
|
|
89
|
-
row.
|
|
93
|
+
row.columnFilters = {}
|
|
90
94
|
|
|
91
95
|
if (resolvedColumnFilters.length) {
|
|
92
96
|
for (let i = 0; i < resolvedColumnFilters.length; i++) {
|
|
93
97
|
currentColumnFilter = resolvedColumnFilters[i]!
|
|
98
|
+
const id = currentColumnFilter.id
|
|
94
99
|
|
|
95
100
|
// Tag the row with the column filter state
|
|
96
|
-
row.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
row.columnFilters[id] = currentColumnFilter.filterFn(
|
|
102
|
+
row,
|
|
103
|
+
id,
|
|
104
|
+
currentColumnFilter.resolvedValue,
|
|
105
|
+
filterMeta => {
|
|
106
|
+
row.columnFiltersMeta[id] = filterMeta
|
|
107
|
+
}
|
|
108
|
+
)
|
|
102
109
|
}
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
if (resolvedGlobalFilters.length) {
|
|
106
113
|
for (let i = 0; i < resolvedGlobalFilters.length; i++) {
|
|
107
114
|
currentGlobalFilter = resolvedGlobalFilters[i]!
|
|
115
|
+
const id = currentGlobalFilter.id
|
|
108
116
|
// Tag the row with the first truthy global filter state
|
|
109
117
|
if (
|
|
110
118
|
currentGlobalFilter.filterFn(
|
|
111
119
|
row,
|
|
112
|
-
|
|
113
|
-
currentGlobalFilter.resolvedValue
|
|
120
|
+
id,
|
|
121
|
+
currentGlobalFilter.resolvedValue,
|
|
122
|
+
filterMeta => {
|
|
123
|
+
row.columnFiltersMeta[id] = filterMeta
|
|
124
|
+
}
|
|
114
125
|
)
|
|
115
126
|
) {
|
|
116
|
-
row.
|
|
127
|
+
row.columnFilters.__global__ = true
|
|
117
128
|
break
|
|
118
129
|
}
|
|
119
130
|
}
|
|
120
131
|
|
|
121
|
-
if (row.
|
|
122
|
-
row.
|
|
132
|
+
if (row.columnFilters.__global__ !== true) {
|
|
133
|
+
row.columnFilters.__global__ = false
|
|
123
134
|
}
|
|
124
135
|
}
|
|
125
136
|
}
|
|
@@ -127,7 +138,7 @@ export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
|
|
|
127
138
|
const filterRowsImpl = (row: Row<TGenerics>) => {
|
|
128
139
|
// Horizontally filter rows through each column
|
|
129
140
|
for (let i = 0; i < filterableIds.length; i++) {
|
|
130
|
-
if (row.
|
|
141
|
+
if (row.columnFilters[filterableIds[i]!] === false) {
|
|
131
142
|
return false
|
|
132
143
|
}
|
|
133
144
|
}
|