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