@tanstack/table-core 8.0.12 → 8.1.0
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/cell.js +13 -13
- package/build/cjs/core/cell.js.map +1 -1
- package/build/cjs/core/column.js +20 -21
- package/build/cjs/core/column.js.map +1 -1
- package/build/cjs/core/headers.js +63 -68
- package/build/cjs/core/headers.js.map +1 -1
- package/build/cjs/core/row.js +16 -11
- package/build/cjs/core/row.js.map +1 -1
- package/build/cjs/core/{instance.js → table.js} +46 -57
- package/build/cjs/core/table.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +36 -36
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +34 -34
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +46 -52
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +24 -49
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Ordering.js +8 -8
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +37 -37
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +33 -33
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +86 -74
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +36 -40
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +30 -30
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/index.js +3 -4
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +8 -8
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +8 -8
- package/build/cjs/utils/getCoreRowModel.js.map +1 -1
- package/build/cjs/utils/getExpandedRowModel.js +4 -4
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedMinMaxValues.js +3 -3
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -1
- package/build/cjs/utils/getFacetedRowModel.js +4 -4
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedUniqueValues.js +3 -3
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -1
- package/build/cjs/utils/getFilteredRowModel.js +8 -8
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +9 -9
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +4 -4
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +7 -7
- package/build/cjs/utils/getSortedRowModel.js.map +1 -1
- package/build/cjs/utils.js +2 -2
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +585 -677
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +352 -377
- package/build/types/index.d.ts +761 -29
- package/build/umd/index.development.js +586 -678
- 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/cell.ts +34 -28
- package/src/core/column.ts +83 -72
- package/src/core/headers.ts +118 -149
- package/src/core/row.ts +31 -25
- package/src/core/{instance.ts → table.ts} +85 -116
- package/src/features/ColumnSizing.ts +45 -47
- package/src/features/Expanding.ts +53 -59
- package/src/features/Filters.ts +112 -132
- package/src/features/Grouping.ts +63 -112
- package/src/features/Ordering.ts +19 -21
- package/src/features/Pagination.ts +54 -55
- package/src/features/Pinning.ts +49 -61
- package/src/features/RowSelection.ts +115 -114
- package/src/features/Sorting.ts +57 -72
- package/src/features/Visibility.ts +48 -48
- package/src/index.ts +1 -2
- package/src/types.ts +64 -69
- package/src/utils/filterRowsUtils.ts +33 -28
- package/src/utils/getCoreRowModel.ts +22 -22
- package/src/utils/getExpandedRowModel.ts +15 -15
- package/src/utils/getFacetedMinMaxValues.ts +6 -6
- package/src/utils/getFacetedRowModel.ts +12 -12
- package/src/utils/getFacetedUniqueValues.ts +6 -6
- package/src/utils/getFilteredRowModel.ts +17 -17
- package/src/utils/getGroupedRowModel.ts +18 -21
- package/src/utils/getPaginationRowModel.ts +10 -13
- package/src/utils/getSortedRowModel.ts +14 -14
- package/src/utils.ts +8 -2
- package/build/cjs/core/instance.js.map +0 -1
- package/build/cjs/createTable.js +0 -72
- package/build/cjs/createTable.js.map +0 -1
- package/build/types/aggregationFns.d.ts +0 -13
- package/build/types/core/cell.d.ts +0 -9
- package/build/types/core/column.d.ts +0 -40
- package/build/types/core/headers.d.ts +0 -46
- package/build/types/core/instance.d.ts +0 -58
- package/build/types/core/row.d.ts +0 -15
- package/build/types/createTable.d.ts +0 -63
- package/build/types/features/ColumnSizing.d.ts +0 -63
- package/build/types/features/Expanding.d.ts +0 -39
- package/build/types/features/Filters.d.ts +0 -90
- package/build/types/features/Grouping.d.ts +0 -68
- package/build/types/features/Ordering.d.ts +0 -18
- package/build/types/features/Pagination.d.ts +0 -42
- package/build/types/features/Pinning.d.ts +0 -40
- package/build/types/features/RowSelection.d.ts +0 -40
- package/build/types/features/Sorting.d.ts +0 -63
- package/build/types/features/Visibility.d.ts +0 -40
- package/build/types/filterFns.d.ts +0 -13
- package/build/types/sortingFns.d.ts +0 -11
- package/build/types/types.d.ts +0 -53
- package/build/types/utils/filterRowsUtils.d.ts +0 -4
- package/build/types/utils/getCoreRowModel.d.ts +0 -2
- package/build/types/utils/getExpandedRowModel.d.ts +0 -7
- package/build/types/utils/getFacetedMinMaxValues.d.ts +0 -2
- package/build/types/utils/getFacetedRowModel.d.ts +0 -2
- package/build/types/utils/getFacetedUniqueValues.d.ts +0 -2
- package/build/types/utils/getFilteredRowModel.d.ts +0 -2
- package/build/types/utils/getGroupedRowModel.d.ts +0 -2
- package/build/types/utils/getPaginationRowModel.d.ts +0 -4
- package/build/types/utils/getSortedRowModel.d.ts +0 -2
- package/build/types/utils.d.ts +0 -19
- package/src/createTable.ts +0 -188
package/src/features/Sorting.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RowModel } from '..'
|
|
2
|
-
import { TableFeature } from '../core/
|
|
2
|
+
import { TableFeature } from '../core/table'
|
|
3
3
|
import {
|
|
4
4
|
BuiltInSortingFn,
|
|
5
5
|
reSplitAlphaNumeric,
|
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
Column,
|
|
11
11
|
OnChangeFn,
|
|
12
12
|
TableGenerics,
|
|
13
|
-
|
|
13
|
+
Table,
|
|
14
14
|
Row,
|
|
15
15
|
Updater,
|
|
16
|
+
RowData,
|
|
16
17
|
} from '../types'
|
|
17
18
|
|
|
18
19
|
import { isFunction, makeStateUpdater, Overwrite } from '../utils'
|
|
@@ -30,23 +31,22 @@ export type SortingTableState = {
|
|
|
30
31
|
sorting: SortingState
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export type SortingFn<
|
|
34
|
-
(rowA: Row<
|
|
34
|
+
export type SortingFn<TData extends RowData> = {
|
|
35
|
+
(rowA: Row<TData>, rowB: Row<TData>, columnId: string): number
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export type CustomSortingFns<
|
|
38
|
+
export type CustomSortingFns<TData extends RowData> = Record<
|
|
38
39
|
string,
|
|
39
|
-
SortingFn<
|
|
40
|
+
SortingFn<TData>
|
|
40
41
|
>
|
|
41
42
|
|
|
42
|
-
export type SortingFnOption<
|
|
43
|
+
export type SortingFnOption<TData extends RowData> =
|
|
43
44
|
| 'auto'
|
|
44
45
|
| BuiltInSortingFn
|
|
45
|
-
|
|
|
46
|
-
| SortingFn<TGenerics>
|
|
46
|
+
| SortingFn<TData>
|
|
47
47
|
|
|
48
|
-
export type SortingColumnDef<
|
|
49
|
-
sortingFn?: SortingFnOption<
|
|
48
|
+
export type SortingColumnDef<TData extends RowData> = {
|
|
49
|
+
sortingFn?: SortingFnOption<TData>
|
|
50
50
|
sortDescFirst?: boolean
|
|
51
51
|
enableSorting?: boolean
|
|
52
52
|
enableMultiSort?: boolean
|
|
@@ -54,10 +54,10 @@ export type SortingColumnDef<TGenerics extends TableGenerics> = {
|
|
|
54
54
|
sortUndefined?: false | -1 | 1
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export type SortingColumn<
|
|
58
|
-
getAutoSortingFn: () => SortingFn<
|
|
57
|
+
export type SortingColumn<TData extends RowData> = {
|
|
58
|
+
getAutoSortingFn: () => SortingFn<TData>
|
|
59
59
|
getAutoSortDir: () => SortDirection
|
|
60
|
-
getSortingFn: () => SortingFn<
|
|
60
|
+
getSortingFn: () => SortingFn<TData>
|
|
61
61
|
getNextSortingOrder: () => SortDirection | false
|
|
62
62
|
getCanSort: () => boolean
|
|
63
63
|
getCanMultiSort: () => boolean
|
|
@@ -68,26 +68,25 @@ export type SortingColumn<TGenerics extends TableGenerics> = {
|
|
|
68
68
|
getToggleSortingHandler: () => undefined | ((event: unknown) => void)
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
export type SortingOptions<
|
|
71
|
+
export type SortingOptions<TData extends RowData> = {
|
|
72
72
|
manualSorting?: boolean
|
|
73
|
-
sortingFns?: TGenerics['SortingFns']
|
|
74
73
|
onSortingChange?: OnChangeFn<SortingState>
|
|
75
74
|
enableSorting?: boolean
|
|
76
75
|
enableSortingRemoval?: boolean
|
|
77
76
|
enableMultiRemove?: boolean
|
|
78
77
|
enableMultiSort?: boolean
|
|
79
78
|
sortDescFirst?: boolean
|
|
80
|
-
getSortedRowModel?: (
|
|
79
|
+
getSortedRowModel?: (table: Table<any>) => () => RowModel<any>
|
|
81
80
|
maxMultiSortColCount?: number
|
|
82
81
|
isMultiSortEvent?: (e: unknown) => boolean
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
export type SortingInstance<
|
|
84
|
+
export type SortingInstance<TData extends RowData> = {
|
|
86
85
|
setSorting: (updater: Updater<SortingState>) => void
|
|
87
86
|
resetSorting: (defaultState?: boolean) => void
|
|
88
|
-
getPreSortedRowModel: () => RowModel<
|
|
89
|
-
getSortedRowModel: () => RowModel<
|
|
90
|
-
_getSortedRowModel?: () => RowModel<
|
|
87
|
+
getPreSortedRowModel: () => RowModel<TData>
|
|
88
|
+
getSortedRowModel: () => RowModel<TData>
|
|
89
|
+
_getSortedRowModel?: () => RowModel<TData>
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
//
|
|
@@ -100,32 +99,30 @@ export const Sorting: TableFeature = {
|
|
|
100
99
|
}
|
|
101
100
|
},
|
|
102
101
|
|
|
103
|
-
getDefaultColumnDef: <
|
|
104
|
-
TGenerics extends TableGenerics
|
|
105
|
-
>(): SortingColumnDef<TGenerics> => {
|
|
102
|
+
getDefaultColumnDef: <TData extends RowData>(): SortingColumnDef<TData> => {
|
|
106
103
|
return {
|
|
107
104
|
sortingFn: 'auto',
|
|
108
105
|
}
|
|
109
106
|
},
|
|
110
107
|
|
|
111
|
-
getDefaultOptions: <
|
|
112
|
-
|
|
113
|
-
): SortingOptions<
|
|
108
|
+
getDefaultOptions: <TData extends RowData>(
|
|
109
|
+
table: Table<TData>
|
|
110
|
+
): SortingOptions<TData> => {
|
|
114
111
|
return {
|
|
115
|
-
onSortingChange: makeStateUpdater('sorting',
|
|
112
|
+
onSortingChange: makeStateUpdater('sorting', table),
|
|
116
113
|
isMultiSortEvent: (e: unknown) => {
|
|
117
114
|
return (e as MouseEvent).shiftKey
|
|
118
115
|
},
|
|
119
116
|
}
|
|
120
117
|
},
|
|
121
118
|
|
|
122
|
-
createColumn: <
|
|
123
|
-
column: Column<
|
|
124
|
-
|
|
125
|
-
): SortingColumn<
|
|
119
|
+
createColumn: <TData extends RowData>(
|
|
120
|
+
column: Column<TData>,
|
|
121
|
+
table: Table<TData>
|
|
122
|
+
): SortingColumn<TData> => {
|
|
126
123
|
return {
|
|
127
124
|
getAutoSortingFn: () => {
|
|
128
|
-
const firstRows =
|
|
125
|
+
const firstRows = table.getFilteredRowModel().flatRows.slice(10)
|
|
129
126
|
|
|
130
127
|
let isString = false
|
|
131
128
|
|
|
@@ -152,7 +149,7 @@ export const Sorting: TableFeature = {
|
|
|
152
149
|
return sortingFns.basic
|
|
153
150
|
},
|
|
154
151
|
getAutoSortDir: () => {
|
|
155
|
-
const firstRow =
|
|
152
|
+
const firstRow = table.getFilteredRowModel().flatRows[0]
|
|
156
153
|
|
|
157
154
|
const value = firstRow?.getValue(column.id)
|
|
158
155
|
|
|
@@ -163,8 +160,6 @@ export const Sorting: TableFeature = {
|
|
|
163
160
|
return 'desc'
|
|
164
161
|
},
|
|
165
162
|
getSortingFn: () => {
|
|
166
|
-
const userSortingFn = instance.options.sortingFns
|
|
167
|
-
|
|
168
163
|
if (!column) {
|
|
169
164
|
throw new Error()
|
|
170
165
|
}
|
|
@@ -173,27 +168,24 @@ export const Sorting: TableFeature = {
|
|
|
173
168
|
? column.columnDef.sortingFn
|
|
174
169
|
: column.columnDef.sortingFn === 'auto'
|
|
175
170
|
? column.getAutoSortingFn()
|
|
176
|
-
: (
|
|
177
|
-
column.columnDef.sortingFn as string
|
|
178
|
-
] ??
|
|
179
|
-
(sortingFns[
|
|
171
|
+
: (sortingFns[
|
|
180
172
|
column.columnDef.sortingFn as BuiltInSortingFn
|
|
181
|
-
] as SortingFn<
|
|
173
|
+
] as SortingFn<TData>)
|
|
182
174
|
},
|
|
183
175
|
toggleSorting: (desc, multi) => {
|
|
184
176
|
// if (column.columns.length) {
|
|
185
177
|
// column.columns.forEach((c, i) => {
|
|
186
178
|
// if (c.id) {
|
|
187
|
-
//
|
|
179
|
+
// table.toggleColumnSorting(c.id, undefined, multi || !!i)
|
|
188
180
|
// }
|
|
189
181
|
// })
|
|
190
182
|
// return
|
|
191
183
|
// }
|
|
192
184
|
|
|
193
|
-
// this needs to be outside of
|
|
185
|
+
// this needs to be outside of table.setSorting to be in sync with rerender
|
|
194
186
|
const nextSortingOrder = column.getNextSortingOrder()
|
|
195
187
|
|
|
196
|
-
|
|
188
|
+
table.setSorting(old => {
|
|
197
189
|
// Find any existing sorting for this column
|
|
198
190
|
const existingSorting = old?.find(d => d.id === column.id)
|
|
199
191
|
const existingIndex = old?.findIndex(d => d.id === column.id)
|
|
@@ -224,9 +216,9 @@ export const Sorting: TableFeature = {
|
|
|
224
216
|
// Handle toggle states that will remove the sorting
|
|
225
217
|
if (
|
|
226
218
|
sortAction === 'toggle' && // Must be toggling
|
|
227
|
-
(
|
|
219
|
+
(table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general
|
|
228
220
|
!hasDescDefined && // Must not be setting desc
|
|
229
|
-
(multi ?
|
|
221
|
+
(multi ? table.options.enableMultiRemove ?? true : true) && // If multi, don't allow if enableMultiRemove
|
|
230
222
|
!nextSortingOrder // Finally, detect if it should indeed be removed
|
|
231
223
|
) {
|
|
232
224
|
sortAction = 'remove'
|
|
@@ -251,8 +243,7 @@ export const Sorting: TableFeature = {
|
|
|
251
243
|
newSorting.splice(
|
|
252
244
|
0,
|
|
253
245
|
newSorting.length -
|
|
254
|
-
(
|
|
255
|
-
Number.MAX_SAFE_INTEGER)
|
|
246
|
+
(table.options.maxMultiSortColCount ?? Number.MAX_SAFE_INTEGER)
|
|
256
247
|
)
|
|
257
248
|
} else if (sortAction === 'toggle' && old?.length) {
|
|
258
249
|
// This flips (or sets) the
|
|
@@ -276,7 +267,7 @@ export const Sorting: TableFeature = {
|
|
|
276
267
|
getNextSortingOrder: () => {
|
|
277
268
|
const sortDescFirst =
|
|
278
269
|
column.columnDef.sortDescFirst ??
|
|
279
|
-
|
|
270
|
+
table.options.sortDescFirst ??
|
|
280
271
|
column.getAutoSortDir() === 'desc'
|
|
281
272
|
const firstSortDirection = sortDescFirst ? 'desc' : 'asc'
|
|
282
273
|
|
|
@@ -294,7 +285,7 @@ export const Sorting: TableFeature = {
|
|
|
294
285
|
getCanSort: () => {
|
|
295
286
|
return (
|
|
296
287
|
(column.columnDef.enableSorting ?? true) &&
|
|
297
|
-
(
|
|
288
|
+
(table.options.enableSorting ?? true) &&
|
|
298
289
|
!!column.accessorFn
|
|
299
290
|
)
|
|
300
291
|
},
|
|
@@ -302,13 +293,13 @@ export const Sorting: TableFeature = {
|
|
|
302
293
|
getCanMultiSort: () => {
|
|
303
294
|
return (
|
|
304
295
|
column.columnDef.enableMultiSort ??
|
|
305
|
-
|
|
296
|
+
table.options.enableMultiSort ??
|
|
306
297
|
!!column.accessorFn
|
|
307
298
|
)
|
|
308
299
|
},
|
|
309
300
|
|
|
310
301
|
getIsSorted: () => {
|
|
311
|
-
const columnSort =
|
|
302
|
+
const columnSort = table
|
|
312
303
|
.getState()
|
|
313
304
|
.sorting?.find(d => d.id === column.id)
|
|
314
305
|
|
|
@@ -316,11 +307,11 @@ export const Sorting: TableFeature = {
|
|
|
316
307
|
},
|
|
317
308
|
|
|
318
309
|
getSortIndex: () =>
|
|
319
|
-
|
|
310
|
+
table.getState().sorting?.findIndex(d => d.id === column.id) ?? -1,
|
|
320
311
|
|
|
321
312
|
clearSorting: () => {
|
|
322
313
|
//clear sorting for just 1 column
|
|
323
|
-
|
|
314
|
+
table.setSorting(old =>
|
|
324
315
|
old?.length ? old.filter(d => d.id !== column.id) : []
|
|
325
316
|
)
|
|
326
317
|
},
|
|
@@ -334,7 +325,7 @@ export const Sorting: TableFeature = {
|
|
|
334
325
|
column.toggleSorting?.(
|
|
335
326
|
undefined,
|
|
336
327
|
column.getCanMultiSort()
|
|
337
|
-
?
|
|
328
|
+
? table.options.isMultiSortEvent?.(e)
|
|
338
329
|
: false
|
|
339
330
|
)
|
|
340
331
|
}
|
|
@@ -342,31 +333,25 @@ export const Sorting: TableFeature = {
|
|
|
342
333
|
}
|
|
343
334
|
},
|
|
344
335
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
): SortingInstance<
|
|
336
|
+
createTable: <TData extends RowData>(
|
|
337
|
+
table: Table<TData>
|
|
338
|
+
): SortingInstance<TData> => {
|
|
348
339
|
return {
|
|
349
|
-
setSorting: updater =>
|
|
340
|
+
setSorting: updater => table.options.onSortingChange?.(updater),
|
|
350
341
|
resetSorting: defaultState => {
|
|
351
|
-
|
|
352
|
-
defaultState ? [] : instance.initialState?.sorting ?? []
|
|
353
|
-
)
|
|
342
|
+
table.setSorting(defaultState ? [] : table.initialState?.sorting ?? [])
|
|
354
343
|
},
|
|
355
|
-
getPreSortedRowModel: () =>
|
|
344
|
+
getPreSortedRowModel: () => table.getGroupedRowModel(),
|
|
356
345
|
getSortedRowModel: () => {
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
instance.options.getSortedRowModel
|
|
360
|
-
) {
|
|
361
|
-
instance._getSortedRowModel =
|
|
362
|
-
instance.options.getSortedRowModel(instance)
|
|
346
|
+
if (!table._getSortedRowModel && table.options.getSortedRowModel) {
|
|
347
|
+
table._getSortedRowModel = table.options.getSortedRowModel(table)
|
|
363
348
|
}
|
|
364
349
|
|
|
365
|
-
if (
|
|
366
|
-
return
|
|
350
|
+
if (table.options.manualSorting || !table._getSortedRowModel) {
|
|
351
|
+
return table.getPreSortedRowModel()
|
|
367
352
|
}
|
|
368
353
|
|
|
369
|
-
return
|
|
354
|
+
return table._getSortedRowModel()
|
|
370
355
|
},
|
|
371
356
|
}
|
|
372
357
|
},
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { TableFeature } from '../core/
|
|
1
|
+
import { TableFeature } from '../core/table'
|
|
2
2
|
import {
|
|
3
3
|
Cell,
|
|
4
4
|
Column,
|
|
5
5
|
OnChangeFn,
|
|
6
6
|
TableGenerics,
|
|
7
|
-
|
|
7
|
+
Table,
|
|
8
8
|
Updater,
|
|
9
9
|
Row,
|
|
10
|
+
RowData,
|
|
10
11
|
} from '../types'
|
|
11
12
|
import { makeStateUpdater, memo } from '../utils'
|
|
12
13
|
|
|
@@ -25,12 +26,12 @@ export type VisibilityDefaultOptions = {
|
|
|
25
26
|
onColumnVisibilityChange: OnChangeFn<VisibilityState>
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
export type VisibilityInstance<
|
|
29
|
-
getVisibleFlatColumns: () => Column<
|
|
30
|
-
getVisibleLeafColumns: () => Column<
|
|
31
|
-
getLeftVisibleLeafColumns: () => Column<
|
|
32
|
-
getRightVisibleLeafColumns: () => Column<
|
|
33
|
-
getCenterVisibleLeafColumns: () => Column<
|
|
29
|
+
export type VisibilityInstance<TData extends RowData> = {
|
|
30
|
+
getVisibleFlatColumns: () => Column<TData>[]
|
|
31
|
+
getVisibleLeafColumns: () => Column<TData>[]
|
|
32
|
+
getLeftVisibleLeafColumns: () => Column<TData>[]
|
|
33
|
+
getRightVisibleLeafColumns: () => Column<TData>[]
|
|
34
|
+
getCenterVisibleLeafColumns: () => Column<TData>[]
|
|
34
35
|
setColumnVisibility: (updater: Updater<VisibilityState>) => void
|
|
35
36
|
resetColumnVisibility: (defaultState?: boolean) => void
|
|
36
37
|
toggleAllColumnsVisible: (value?: boolean) => void
|
|
@@ -43,9 +44,9 @@ export type VisibilityColumnDef = {
|
|
|
43
44
|
enableHiding?: boolean
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
export type VisibilityRow<
|
|
47
|
-
_getAllVisibleCells: () => Cell<
|
|
48
|
-
getVisibleCells: () => Cell<
|
|
47
|
+
export type VisibilityRow<TData extends RowData> = {
|
|
48
|
+
_getAllVisibleCells: () => Cell<TData>[]
|
|
49
|
+
getVisibleCells: () => Cell<TData>[]
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
export type VisibilityColumn = {
|
|
@@ -65,35 +66,35 @@ export const Visibility: TableFeature = {
|
|
|
65
66
|
}
|
|
66
67
|
},
|
|
67
68
|
|
|
68
|
-
getDefaultOptions: <
|
|
69
|
-
|
|
69
|
+
getDefaultOptions: <TData extends RowData>(
|
|
70
|
+
table: Table<TData>
|
|
70
71
|
): VisibilityDefaultOptions => {
|
|
71
72
|
return {
|
|
72
|
-
onColumnVisibilityChange: makeStateUpdater('columnVisibility',
|
|
73
|
+
onColumnVisibilityChange: makeStateUpdater('columnVisibility', table),
|
|
73
74
|
}
|
|
74
75
|
},
|
|
75
76
|
|
|
76
|
-
createColumn: <
|
|
77
|
-
column: Column<
|
|
78
|
-
|
|
77
|
+
createColumn: <TData extends RowData>(
|
|
78
|
+
column: Column<TData>,
|
|
79
|
+
table: Table<TData>
|
|
79
80
|
): VisibilityColumn => {
|
|
80
81
|
return {
|
|
81
82
|
toggleVisibility: value => {
|
|
82
83
|
if (column.getCanHide()) {
|
|
83
|
-
|
|
84
|
+
table.setColumnVisibility(old => ({
|
|
84
85
|
...old,
|
|
85
86
|
[column.id]: value ?? !column.getIsVisible(),
|
|
86
87
|
}))
|
|
87
88
|
}
|
|
88
89
|
},
|
|
89
90
|
getIsVisible: () => {
|
|
90
|
-
return
|
|
91
|
+
return table.getState().columnVisibility?.[column.id] ?? true
|
|
91
92
|
},
|
|
92
93
|
|
|
93
94
|
getCanHide: () => {
|
|
94
95
|
return (
|
|
95
96
|
(column.columnDef.enableHiding ?? true) &&
|
|
96
|
-
(
|
|
97
|
+
(table.options.enableHiding ?? true)
|
|
97
98
|
)
|
|
98
99
|
},
|
|
99
100
|
getToggleVisibilityHandler: () => {
|
|
@@ -106,20 +107,20 @@ export const Visibility: TableFeature = {
|
|
|
106
107
|
}
|
|
107
108
|
},
|
|
108
109
|
|
|
109
|
-
createRow: <
|
|
110
|
-
row: Row<
|
|
111
|
-
|
|
112
|
-
): VisibilityRow<
|
|
110
|
+
createRow: <TData extends RowData>(
|
|
111
|
+
row: Row<TData>,
|
|
112
|
+
table: Table<TData>
|
|
113
|
+
): VisibilityRow<TData> => {
|
|
113
114
|
return {
|
|
114
115
|
_getAllVisibleCells: memo(
|
|
115
|
-
() => [row.getAllCells(),
|
|
116
|
+
() => [row.getAllCells(), table.getState().columnVisibility],
|
|
116
117
|
cells => {
|
|
117
118
|
return cells.filter(cell => cell.column.getIsVisible())
|
|
118
119
|
},
|
|
119
120
|
{
|
|
120
121
|
key:
|
|
121
122
|
process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
|
|
122
|
-
debug: () =>
|
|
123
|
+
debug: () => table.options.debugAll ?? table.options.debugRows,
|
|
123
124
|
}
|
|
124
125
|
),
|
|
125
126
|
getVisibleCells: memo(
|
|
@@ -131,19 +132,19 @@ export const Visibility: TableFeature = {
|
|
|
131
132
|
(left, center, right) => [...left, ...center, ...right],
|
|
132
133
|
{
|
|
133
134
|
key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
|
|
134
|
-
debug: () =>
|
|
135
|
+
debug: () => table.options.debugAll ?? table.options.debugRows,
|
|
135
136
|
}
|
|
136
137
|
),
|
|
137
138
|
}
|
|
138
139
|
},
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
): VisibilityInstance<
|
|
141
|
+
createTable: <TData extends RowData>(
|
|
142
|
+
table: Table<TData>
|
|
143
|
+
): VisibilityInstance<TData> => {
|
|
143
144
|
const makeVisibleColumnsMethod = (
|
|
144
145
|
key: string,
|
|
145
|
-
getColumns: () => Column<
|
|
146
|
-
): (() => Column<
|
|
146
|
+
getColumns: () => Column<TData>[]
|
|
147
|
+
): (() => Column<TData>[]) => {
|
|
147
148
|
return memo(
|
|
148
149
|
() => [
|
|
149
150
|
getColumns(),
|
|
@@ -157,8 +158,7 @@ export const Visibility: TableFeature = {
|
|
|
157
158
|
},
|
|
158
159
|
{
|
|
159
160
|
key,
|
|
160
|
-
debug: () =>
|
|
161
|
-
instance.options.debugAll ?? instance.options.debugColumns,
|
|
161
|
+
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
162
162
|
}
|
|
163
163
|
)
|
|
164
164
|
}
|
|
@@ -166,39 +166,39 @@ export const Visibility: TableFeature = {
|
|
|
166
166
|
return {
|
|
167
167
|
getVisibleFlatColumns: makeVisibleColumnsMethod(
|
|
168
168
|
'getVisibleFlatColumns',
|
|
169
|
-
() =>
|
|
169
|
+
() => table.getAllFlatColumns()
|
|
170
170
|
),
|
|
171
171
|
getVisibleLeafColumns: makeVisibleColumnsMethod(
|
|
172
172
|
'getVisibleLeafColumns',
|
|
173
|
-
() =>
|
|
173
|
+
() => table.getAllLeafColumns()
|
|
174
174
|
),
|
|
175
175
|
getLeftVisibleLeafColumns: makeVisibleColumnsMethod(
|
|
176
176
|
'getLeftVisibleLeafColumns',
|
|
177
|
-
() =>
|
|
177
|
+
() => table.getLeftLeafColumns()
|
|
178
178
|
),
|
|
179
179
|
getRightVisibleLeafColumns: makeVisibleColumnsMethod(
|
|
180
180
|
'getRightVisibleLeafColumns',
|
|
181
|
-
() =>
|
|
181
|
+
() => table.getRightLeafColumns()
|
|
182
182
|
),
|
|
183
183
|
getCenterVisibleLeafColumns: makeVisibleColumnsMethod(
|
|
184
184
|
'getCenterVisibleLeafColumns',
|
|
185
|
-
() =>
|
|
185
|
+
() => table.getCenterLeafColumns()
|
|
186
186
|
),
|
|
187
187
|
|
|
188
188
|
setColumnVisibility: updater =>
|
|
189
|
-
|
|
189
|
+
table.options.onColumnVisibilityChange?.(updater),
|
|
190
190
|
|
|
191
191
|
resetColumnVisibility: defaultState => {
|
|
192
|
-
|
|
193
|
-
defaultState ? {} :
|
|
192
|
+
table.setColumnVisibility(
|
|
193
|
+
defaultState ? {} : table.initialState.columnVisibility ?? {}
|
|
194
194
|
)
|
|
195
195
|
},
|
|
196
196
|
|
|
197
197
|
toggleAllColumnsVisible: value => {
|
|
198
|
-
value = value ?? !
|
|
198
|
+
value = value ?? !table.getIsAllColumnsVisible()
|
|
199
199
|
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
table.setColumnVisibility(
|
|
201
|
+
table.getAllLeafColumns().reduce(
|
|
202
202
|
(obj, column) => ({
|
|
203
203
|
...obj,
|
|
204
204
|
[column.id]: !value ? !column.getCanHide?.() : value,
|
|
@@ -209,14 +209,14 @@ export const Visibility: TableFeature = {
|
|
|
209
209
|
},
|
|
210
210
|
|
|
211
211
|
getIsAllColumnsVisible: () =>
|
|
212
|
-
!
|
|
212
|
+
!table.getAllLeafColumns().some(column => !column.getIsVisible?.()),
|
|
213
213
|
|
|
214
214
|
getIsSomeColumnsVisible: () =>
|
|
215
|
-
|
|
215
|
+
table.getAllLeafColumns().some(column => column.getIsVisible?.()),
|
|
216
216
|
|
|
217
217
|
getToggleAllColumnsVisibilityHandler: () => {
|
|
218
218
|
return (e: unknown) => {
|
|
219
|
-
|
|
219
|
+
table.toggleAllColumnsVisible(
|
|
220
220
|
((e as MouseEvent).target as HTMLInputElement)?.checked
|
|
221
221
|
)
|
|
222
222
|
}
|