@tanstack/table-core 8.0.11 → 8.0.14
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 +67 -67
- 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 +2 -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 +567 -670
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +1092 -0
- package/build/types/index.d.ts +759 -0
- package/build/umd/index.development.js +567 -671
- 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 +2 -2
- 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 +97 -108
- 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/src/createTable.ts +0 -188
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { TableFeature } from '../core/
|
|
1
|
+
import { TableFeature } from '../core/table'
|
|
2
2
|
import {
|
|
3
3
|
OnChangeFn,
|
|
4
4
|
TableGenerics,
|
|
5
|
-
|
|
5
|
+
Table,
|
|
6
6
|
Row,
|
|
7
7
|
RowModel,
|
|
8
8
|
Updater,
|
|
9
|
+
RowData,
|
|
9
10
|
} from '../types'
|
|
10
11
|
import { makeStateUpdater, memo } from '../utils'
|
|
11
12
|
|
|
@@ -15,28 +16,22 @@ export type RowSelectionTableState = {
|
|
|
15
16
|
rowSelection: RowSelectionState
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export type RowSelectionOptions<
|
|
19
|
-
enableRowSelection?: boolean | ((row: Row<
|
|
20
|
-
enableMultiRowSelection?: boolean | ((row: Row<
|
|
21
|
-
enableSubRowSelection?: boolean | ((row: Row<
|
|
19
|
+
export type RowSelectionOptions<TData extends RowData> = {
|
|
20
|
+
enableRowSelection?: boolean | ((row: Row<TData>) => boolean)
|
|
21
|
+
enableMultiRowSelection?: boolean | ((row: Row<TData>) => boolean)
|
|
22
|
+
enableSubRowSelection?: boolean | ((row: Row<TData>) => boolean)
|
|
22
23
|
onRowSelectionChange?: OnChangeFn<RowSelectionState>
|
|
23
24
|
// enableGroupingRowSelection?:
|
|
24
25
|
// | boolean
|
|
25
26
|
// | ((
|
|
26
|
-
// row: Row<
|
|
27
|
+
// row: Row<TData>
|
|
27
28
|
// ) => boolean)
|
|
28
29
|
// isAdditiveSelectEvent?: (e: unknown) => boolean
|
|
29
30
|
// isInclusiveSelectEvent?: (e: unknown) => boolean
|
|
30
31
|
// selectRowsFn?: (
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
// TFilterFns,
|
|
35
|
-
// TSortingFns,
|
|
36
|
-
// TAggregationFns
|
|
37
|
-
// >,
|
|
38
|
-
// rowModel: RowModel<TGenerics>
|
|
39
|
-
// ) => RowModel<TGenerics>
|
|
32
|
+
// table: Table<TData>,
|
|
33
|
+
// rowModel: RowModel<TData>
|
|
34
|
+
// ) => RowModel<TData>
|
|
40
35
|
}
|
|
41
36
|
|
|
42
37
|
export type RowSelectionRow = {
|
|
@@ -49,7 +44,7 @@ export type RowSelectionRow = {
|
|
|
49
44
|
getToggleSelectedHandler: () => (event: unknown) => void
|
|
50
45
|
}
|
|
51
46
|
|
|
52
|
-
export type RowSelectionInstance<
|
|
47
|
+
export type RowSelectionInstance<TData extends RowData> = {
|
|
53
48
|
getToggleAllRowsSelectedHandler: () => (event: unknown) => void
|
|
54
49
|
getToggleAllPageRowsSelectedHandler: () => (event: unknown) => void
|
|
55
50
|
setRowSelection: (updater: Updater<RowSelectionState>) => void
|
|
@@ -60,10 +55,10 @@ export type RowSelectionInstance<TGenerics extends TableGenerics> = {
|
|
|
60
55
|
getIsSomePageRowsSelected: () => boolean
|
|
61
56
|
toggleAllRowsSelected: (value?: boolean) => void
|
|
62
57
|
toggleAllPageRowsSelected: (value?: boolean) => void
|
|
63
|
-
getPreSelectedRowModel: () => RowModel<
|
|
64
|
-
getSelectedRowModel: () => RowModel<
|
|
65
|
-
getFilteredSelectedRowModel: () => RowModel<
|
|
66
|
-
getGroupedSelectedRowModel: () => RowModel<
|
|
58
|
+
getPreSelectedRowModel: () => RowModel<TData>
|
|
59
|
+
getSelectedRowModel: () => RowModel<TData>
|
|
60
|
+
getFilteredSelectedRowModel: () => RowModel<TData>
|
|
61
|
+
getGroupedSelectedRowModel: () => RowModel<TData>
|
|
67
62
|
}
|
|
68
63
|
|
|
69
64
|
//
|
|
@@ -76,11 +71,11 @@ export const RowSelection: TableFeature = {
|
|
|
76
71
|
}
|
|
77
72
|
},
|
|
78
73
|
|
|
79
|
-
getDefaultOptions: <
|
|
80
|
-
|
|
81
|
-
): RowSelectionOptions<
|
|
74
|
+
getDefaultOptions: <TData extends RowData>(
|
|
75
|
+
table: Table<TData>
|
|
76
|
+
): RowSelectionOptions<TData> => {
|
|
82
77
|
return {
|
|
83
|
-
onRowSelectionChange: makeStateUpdater('rowSelection',
|
|
78
|
+
onRowSelectionChange: makeStateUpdater('rowSelection', table),
|
|
84
79
|
enableRowSelection: true,
|
|
85
80
|
enableMultiRowSelection: true,
|
|
86
81
|
enableSubRowSelection: true,
|
|
@@ -90,26 +85,23 @@ export const RowSelection: TableFeature = {
|
|
|
90
85
|
}
|
|
91
86
|
},
|
|
92
87
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
): RowSelectionInstance<
|
|
88
|
+
createTable: <TData extends RowData>(
|
|
89
|
+
table: Table<TData>
|
|
90
|
+
): RowSelectionInstance<TData> => {
|
|
96
91
|
return {
|
|
97
|
-
setRowSelection: updater =>
|
|
98
|
-
instance.options.onRowSelectionChange?.(updater),
|
|
92
|
+
setRowSelection: updater => table.options.onRowSelectionChange?.(updater),
|
|
99
93
|
resetRowSelection: defaultState =>
|
|
100
|
-
|
|
101
|
-
defaultState ? {} :
|
|
94
|
+
table.setRowSelection(
|
|
95
|
+
defaultState ? {} : table.initialState.rowSelection ?? {}
|
|
102
96
|
),
|
|
103
97
|
toggleAllRowsSelected: value => {
|
|
104
|
-
|
|
98
|
+
table.setRowSelection(old => {
|
|
105
99
|
value =
|
|
106
|
-
typeof value !== 'undefined'
|
|
107
|
-
? value
|
|
108
|
-
: !instance.getIsAllRowsSelected()
|
|
100
|
+
typeof value !== 'undefined' ? value : !table.getIsAllRowsSelected()
|
|
109
101
|
|
|
110
102
|
const rowSelection = { ...old }
|
|
111
103
|
|
|
112
|
-
const preGroupedFlatRows =
|
|
104
|
+
const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows
|
|
113
105
|
|
|
114
106
|
// We don't use `mutateRowIsSelected` here for performance reasons.
|
|
115
107
|
// All of the rows are flat already, so it wouldn't be worth it
|
|
@@ -127,16 +119,16 @@ export const RowSelection: TableFeature = {
|
|
|
127
119
|
})
|
|
128
120
|
},
|
|
129
121
|
toggleAllPageRowsSelected: value =>
|
|
130
|
-
|
|
122
|
+
table.setRowSelection(old => {
|
|
131
123
|
const resolvedValue =
|
|
132
124
|
typeof value !== 'undefined'
|
|
133
125
|
? value
|
|
134
|
-
: !
|
|
126
|
+
: !table.getIsAllPageRowsSelected()
|
|
135
127
|
|
|
136
128
|
const rowSelection: RowSelectionState = { ...old }
|
|
137
129
|
|
|
138
|
-
|
|
139
|
-
mutateRowIsSelected(rowSelection, row.id, resolvedValue,
|
|
130
|
+
table.getRowModel().rows.forEach(row => {
|
|
131
|
+
mutateRowIsSelected(rowSelection, row.id, resolvedValue, table)
|
|
140
132
|
})
|
|
141
133
|
|
|
142
134
|
return rowSelection
|
|
@@ -147,7 +139,7 @@ export const RowSelection: TableFeature = {
|
|
|
147
139
|
// rows,
|
|
148
140
|
// rowsById,
|
|
149
141
|
// options: { selectGroupingRows, selectSubRows },
|
|
150
|
-
// } =
|
|
142
|
+
// } = table
|
|
151
143
|
|
|
152
144
|
// const findSelectedRow = (rows: Row[]) => {
|
|
153
145
|
// let found
|
|
@@ -180,7 +172,7 @@ export const RowSelection: TableFeature = {
|
|
|
180
172
|
// })
|
|
181
173
|
// }
|
|
182
174
|
|
|
183
|
-
//
|
|
175
|
+
// table.rows.forEach(row => {
|
|
184
176
|
// const isFirstRow = row.id === firstRow.id
|
|
185
177
|
// const isLastRow = row.id === lastRow.id
|
|
186
178
|
|
|
@@ -198,11 +190,11 @@ export const RowSelection: TableFeature = {
|
|
|
198
190
|
// }
|
|
199
191
|
// })
|
|
200
192
|
|
|
201
|
-
//
|
|
193
|
+
// table.setRowSelection(selectedRowIds)
|
|
202
194
|
// },
|
|
203
|
-
getPreSelectedRowModel: () =>
|
|
195
|
+
getPreSelectedRowModel: () => table.getCoreRowModel(),
|
|
204
196
|
getSelectedRowModel: memo(
|
|
205
|
-
() => [
|
|
197
|
+
() => [table.getState().rowSelection, table.getCoreRowModel()],
|
|
206
198
|
(rowSelection, rowModel) => {
|
|
207
199
|
if (!Object.keys(rowSelection).length) {
|
|
208
200
|
return {
|
|
@@ -212,19 +204,16 @@ export const RowSelection: TableFeature = {
|
|
|
212
204
|
}
|
|
213
205
|
}
|
|
214
206
|
|
|
215
|
-
return selectRowsFn(
|
|
207
|
+
return selectRowsFn(table, rowModel)
|
|
216
208
|
},
|
|
217
209
|
{
|
|
218
210
|
key: process.env.NODE_ENV === 'development' && 'getSelectedRowModel',
|
|
219
|
-
debug: () =>
|
|
211
|
+
debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
220
212
|
}
|
|
221
213
|
),
|
|
222
214
|
|
|
223
215
|
getFilteredSelectedRowModel: memo(
|
|
224
|
-
() => [
|
|
225
|
-
instance.getState().rowSelection,
|
|
226
|
-
instance.getFilteredRowModel(),
|
|
227
|
-
],
|
|
216
|
+
() => [table.getState().rowSelection, table.getFilteredRowModel()],
|
|
228
217
|
(rowSelection, rowModel) => {
|
|
229
218
|
if (!Object.keys(rowSelection).length) {
|
|
230
219
|
return {
|
|
@@ -234,18 +223,18 @@ export const RowSelection: TableFeature = {
|
|
|
234
223
|
}
|
|
235
224
|
}
|
|
236
225
|
|
|
237
|
-
return selectRowsFn(
|
|
226
|
+
return selectRowsFn(table, rowModel)
|
|
238
227
|
},
|
|
239
228
|
{
|
|
240
229
|
key:
|
|
241
230
|
process.env.NODE_ENV === 'production' &&
|
|
242
231
|
'getFilteredSelectedRowModel',
|
|
243
|
-
debug: () =>
|
|
232
|
+
debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
244
233
|
}
|
|
245
234
|
),
|
|
246
235
|
|
|
247
236
|
getGroupedSelectedRowModel: memo(
|
|
248
|
-
() => [
|
|
237
|
+
() => [table.getState().rowSelection, table.getSortedRowModel()],
|
|
249
238
|
(rowSelection, rowModel) => {
|
|
250
239
|
if (!Object.keys(rowSelection).length) {
|
|
251
240
|
return {
|
|
@@ -255,35 +244,35 @@ export const RowSelection: TableFeature = {
|
|
|
255
244
|
}
|
|
256
245
|
}
|
|
257
246
|
|
|
258
|
-
return selectRowsFn(
|
|
247
|
+
return selectRowsFn(table, rowModel)
|
|
259
248
|
},
|
|
260
249
|
{
|
|
261
250
|
key:
|
|
262
251
|
process.env.NODE_ENV === 'production' &&
|
|
263
252
|
'getGroupedSelectedRowModel',
|
|
264
|
-
debug: () =>
|
|
253
|
+
debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
265
254
|
}
|
|
266
255
|
),
|
|
267
256
|
|
|
268
257
|
///
|
|
269
258
|
|
|
270
259
|
// getGroupingRowCanSelect: rowId => {
|
|
271
|
-
// const row =
|
|
260
|
+
// const row = table.getRow(rowId)
|
|
272
261
|
|
|
273
262
|
// if (!row) {
|
|
274
263
|
// throw new Error()
|
|
275
264
|
// }
|
|
276
265
|
|
|
277
|
-
// if (typeof
|
|
278
|
-
// return
|
|
266
|
+
// if (typeof table.options.enableGroupingRowSelection === 'function') {
|
|
267
|
+
// return table.options.enableGroupingRowSelection(row)
|
|
279
268
|
// }
|
|
280
269
|
|
|
281
|
-
// return
|
|
270
|
+
// return table.options.enableGroupingRowSelection ?? false
|
|
282
271
|
// },
|
|
283
272
|
|
|
284
273
|
getIsAllRowsSelected: () => {
|
|
285
|
-
const preFilteredFlatRows =
|
|
286
|
-
const { rowSelection } =
|
|
274
|
+
const preFilteredFlatRows = table.getPreFilteredRowModel().flatRows
|
|
275
|
+
const { rowSelection } = table.getState()
|
|
287
276
|
|
|
288
277
|
let isAllRowsSelected = Boolean(
|
|
289
278
|
preFilteredFlatRows.length && Object.keys(rowSelection).length
|
|
@@ -299,8 +288,8 @@ export const RowSelection: TableFeature = {
|
|
|
299
288
|
},
|
|
300
289
|
|
|
301
290
|
getIsAllPageRowsSelected: () => {
|
|
302
|
-
const paginationFlatRows =
|
|
303
|
-
const { rowSelection } =
|
|
291
|
+
const paginationFlatRows = table.getPaginationRowModel().flatRows
|
|
292
|
+
const { rowSelection } = table.getState()
|
|
304
293
|
|
|
305
294
|
let isAllPageRowsSelected = !!paginationFlatRows.length
|
|
306
295
|
|
|
@@ -316,14 +305,14 @@ export const RowSelection: TableFeature = {
|
|
|
316
305
|
|
|
317
306
|
getIsSomeRowsSelected: () => {
|
|
318
307
|
return (
|
|
319
|
-
!
|
|
320
|
-
!!Object.keys(
|
|
308
|
+
!table.getIsAllRowsSelected() &&
|
|
309
|
+
!!Object.keys(table.getState().rowSelection ?? {}).length
|
|
321
310
|
)
|
|
322
311
|
},
|
|
323
312
|
|
|
324
313
|
getIsSomePageRowsSelected: () => {
|
|
325
|
-
const paginationFlatRows =
|
|
326
|
-
return
|
|
314
|
+
const paginationFlatRows = table.getPaginationRowModel().flatRows
|
|
315
|
+
return table.getIsAllPageRowsSelected()
|
|
327
316
|
? false
|
|
328
317
|
: paginationFlatRows.some(
|
|
329
318
|
d => d.getIsSelected() || d.getIsSomeSelected()
|
|
@@ -332,7 +321,7 @@ export const RowSelection: TableFeature = {
|
|
|
332
321
|
|
|
333
322
|
getToggleAllRowsSelectedHandler: () => {
|
|
334
323
|
return (e: unknown) => {
|
|
335
|
-
|
|
324
|
+
table.toggleAllRowsSelected(
|
|
336
325
|
((e as MouseEvent).target as HTMLInputElement).checked
|
|
337
326
|
)
|
|
338
327
|
}
|
|
@@ -340,7 +329,7 @@ export const RowSelection: TableFeature = {
|
|
|
340
329
|
|
|
341
330
|
getToggleAllPageRowsSelectedHandler: () => {
|
|
342
331
|
return (e: unknown) => {
|
|
343
|
-
|
|
332
|
+
table.toggleAllPageRowsSelected(
|
|
344
333
|
((e as MouseEvent).target as HTMLInputElement).checked
|
|
345
334
|
)
|
|
346
335
|
}
|
|
@@ -348,15 +337,15 @@ export const RowSelection: TableFeature = {
|
|
|
348
337
|
}
|
|
349
338
|
},
|
|
350
339
|
|
|
351
|
-
createRow: <
|
|
352
|
-
row: Row<
|
|
353
|
-
|
|
340
|
+
createRow: <TData extends RowData>(
|
|
341
|
+
row: Row<TData>,
|
|
342
|
+
table: Table<TData>
|
|
354
343
|
): RowSelectionRow => {
|
|
355
344
|
return {
|
|
356
345
|
toggleSelected: value => {
|
|
357
346
|
const isSelected = row.getIsSelected()
|
|
358
347
|
|
|
359
|
-
|
|
348
|
+
table.setRowSelection(old => {
|
|
360
349
|
value = typeof value !== 'undefined' ? value : !isSelected
|
|
361
350
|
|
|
362
351
|
if (isSelected === value) {
|
|
@@ -365,43 +354,43 @@ export const RowSelection: TableFeature = {
|
|
|
365
354
|
|
|
366
355
|
const selectedRowIds = { ...old }
|
|
367
356
|
|
|
368
|
-
mutateRowIsSelected(selectedRowIds, row.id, value,
|
|
357
|
+
mutateRowIsSelected(selectedRowIds, row.id, value, table)
|
|
369
358
|
|
|
370
359
|
return selectedRowIds
|
|
371
360
|
})
|
|
372
361
|
},
|
|
373
362
|
getIsSelected: () => {
|
|
374
|
-
const { rowSelection } =
|
|
375
|
-
return isRowSelected(row, rowSelection,
|
|
363
|
+
const { rowSelection } = table.getState()
|
|
364
|
+
return isRowSelected(row, rowSelection, table) === true
|
|
376
365
|
},
|
|
377
366
|
|
|
378
367
|
getIsSomeSelected: () => {
|
|
379
|
-
const { rowSelection } =
|
|
380
|
-
return isRowSelected(row, rowSelection,
|
|
368
|
+
const { rowSelection } = table.getState()
|
|
369
|
+
return isRowSelected(row, rowSelection, table) === 'some'
|
|
381
370
|
},
|
|
382
371
|
|
|
383
372
|
getCanSelect: () => {
|
|
384
|
-
if (typeof
|
|
385
|
-
return
|
|
373
|
+
if (typeof table.options.enableRowSelection === 'function') {
|
|
374
|
+
return table.options.enableRowSelection(row)
|
|
386
375
|
}
|
|
387
376
|
|
|
388
|
-
return
|
|
377
|
+
return table.options.enableRowSelection ?? true
|
|
389
378
|
},
|
|
390
379
|
|
|
391
380
|
getCanSelectSubRows: () => {
|
|
392
|
-
if (typeof
|
|
393
|
-
return
|
|
381
|
+
if (typeof table.options.enableSubRowSelection === 'function') {
|
|
382
|
+
return table.options.enableSubRowSelection(row)
|
|
394
383
|
}
|
|
395
384
|
|
|
396
|
-
return
|
|
385
|
+
return table.options.enableSubRowSelection ?? true
|
|
397
386
|
},
|
|
398
387
|
|
|
399
388
|
getCanMultiSelect: () => {
|
|
400
|
-
if (typeof
|
|
401
|
-
return
|
|
389
|
+
if (typeof table.options.enableMultiRowSelection === 'function') {
|
|
390
|
+
return table.options.enableMultiRowSelection(row)
|
|
402
391
|
}
|
|
403
392
|
|
|
404
|
-
return
|
|
393
|
+
return table.options.enableMultiRowSelection ?? true
|
|
405
394
|
},
|
|
406
395
|
getToggleSelectedHandler: () => {
|
|
407
396
|
const canSelect = row.getCanSelect()
|
|
@@ -417,19 +406,19 @@ export const RowSelection: TableFeature = {
|
|
|
417
406
|
},
|
|
418
407
|
}
|
|
419
408
|
|
|
420
|
-
const mutateRowIsSelected = <
|
|
409
|
+
const mutateRowIsSelected = <TData extends RowData>(
|
|
421
410
|
selectedRowIds: Record<string, boolean>,
|
|
422
411
|
id: string,
|
|
423
412
|
value: boolean,
|
|
424
|
-
|
|
413
|
+
table: Table<TData>
|
|
425
414
|
) => {
|
|
426
|
-
const row =
|
|
415
|
+
const row = table.getRow(id)
|
|
427
416
|
|
|
428
417
|
const isGrouped = row.getIsGrouped()
|
|
429
418
|
|
|
430
419
|
// if ( // TODO: enforce grouping row selection rules
|
|
431
420
|
// !isGrouped ||
|
|
432
|
-
// (isGrouped &&
|
|
421
|
+
// (isGrouped && table.options.enableGroupingRowSelection)
|
|
433
422
|
// ) {
|
|
434
423
|
if (value) {
|
|
435
424
|
selectedRowIds[id] = true
|
|
@@ -440,25 +429,25 @@ const mutateRowIsSelected = <TGenerics extends TableGenerics>(
|
|
|
440
429
|
|
|
441
430
|
if (row.subRows?.length && row.getCanSelectSubRows()) {
|
|
442
431
|
row.subRows.forEach(row =>
|
|
443
|
-
mutateRowIsSelected(selectedRowIds, row.id, value,
|
|
432
|
+
mutateRowIsSelected(selectedRowIds, row.id, value, table)
|
|
444
433
|
)
|
|
445
434
|
}
|
|
446
435
|
}
|
|
447
436
|
|
|
448
|
-
export function selectRowsFn<
|
|
449
|
-
|
|
450
|
-
rowModel: RowModel<
|
|
451
|
-
): RowModel<
|
|
452
|
-
const rowSelection =
|
|
437
|
+
export function selectRowsFn<TData extends RowData>(
|
|
438
|
+
table: Table<TData>,
|
|
439
|
+
rowModel: RowModel<TData>
|
|
440
|
+
): RowModel<TData> {
|
|
441
|
+
const rowSelection = table.getState().rowSelection
|
|
453
442
|
|
|
454
|
-
const newSelectedFlatRows: Row<
|
|
455
|
-
const newSelectedRowsById: Record<string, Row<
|
|
443
|
+
const newSelectedFlatRows: Row<TData>[] = []
|
|
444
|
+
const newSelectedRowsById: Record<string, Row<TData>> = {}
|
|
456
445
|
|
|
457
446
|
// Filters top level and nested rows
|
|
458
|
-
const recurseRows = (rows: Row<
|
|
447
|
+
const recurseRows = (rows: Row<TData>[], depth = 0): Row<TData>[] => {
|
|
459
448
|
return rows
|
|
460
449
|
.map(row => {
|
|
461
|
-
const isSelected = isRowSelected(row, rowSelection,
|
|
450
|
+
const isSelected = isRowSelected(row, rowSelection, table) === true
|
|
462
451
|
|
|
463
452
|
if (isSelected) {
|
|
464
453
|
newSelectedFlatRows.push(row)
|
|
@@ -476,7 +465,7 @@ export function selectRowsFn<TGenerics extends TableGenerics>(
|
|
|
476
465
|
return row
|
|
477
466
|
}
|
|
478
467
|
})
|
|
479
|
-
.filter(Boolean) as Row<
|
|
468
|
+
.filter(Boolean) as Row<TData>[]
|
|
480
469
|
}
|
|
481
470
|
|
|
482
471
|
return {
|
|
@@ -486,10 +475,10 @@ export function selectRowsFn<TGenerics extends TableGenerics>(
|
|
|
486
475
|
}
|
|
487
476
|
}
|
|
488
477
|
|
|
489
|
-
export function isRowSelected<
|
|
490
|
-
row: Row<
|
|
478
|
+
export function isRowSelected<TData extends RowData>(
|
|
479
|
+
row: Row<TData>,
|
|
491
480
|
selection: Record<string, boolean>,
|
|
492
|
-
|
|
481
|
+
table: Table<TData>
|
|
493
482
|
): boolean | 'some' {
|
|
494
483
|
if (selection[row.id]) {
|
|
495
484
|
return true
|
|
@@ -505,7 +494,7 @@ export function isRowSelected<TGenerics extends TableGenerics>(
|
|
|
505
494
|
return
|
|
506
495
|
}
|
|
507
496
|
|
|
508
|
-
if (isRowSelected(subRow, selection,
|
|
497
|
+
if (isRowSelected(subRow, selection, table)) {
|
|
509
498
|
someSelected = true
|
|
510
499
|
} else {
|
|
511
500
|
allChildrenSelected = false
|