@tanstack/table-core 8.0.0-alpha.54 → 8.0.0-alpha.58
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 +9 -384
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/features/Cells.js +122 -0
- package/build/cjs/features/Cells.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +90 -37
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js +216 -0
- package/build/cjs/features/Columns.js.map +1 -0
- package/build/cjs/features/Expanding.js +2 -2
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +3 -3
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +2 -2
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +78 -153
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js +1 -1
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +2 -2
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +172 -2
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +1 -1
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +99 -0
- package/build/cjs/features/Rows.js.map +1 -0
- package/build/cjs/features/Sorting.js +2 -2
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +51 -17
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +881 -695
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +418 -316
- package/build/types/core.d.ts +2 -79
- package/build/types/features/Cells.d.ts +14 -0
- package/build/types/features/ColumnSizing.d.ts +26 -18
- package/build/types/features/Columns.d.ts +54 -0
- package/build/types/features/Expanding.d.ts +2 -1
- package/build/types/features/Filters.d.ts +3 -1
- package/build/types/features/Grouping.d.ts +2 -1
- package/build/types/features/Headers.d.ts +3 -11
- package/build/types/features/Ordering.d.ts +1 -1
- package/build/types/features/Pagination.d.ts +2 -1
- package/build/types/features/Pinning.d.ts +18 -4
- package/build/types/features/RowSelection.d.ts +1 -1
- package/build/types/features/Rows.d.ts +29 -0
- package/build/types/features/Sorting.d.ts +2 -1
- package/build/types/features/Visibility.d.ts +7 -2
- package/build/types/types.d.ts +18 -10
- package/build/types/utils.d.ts +0 -1
- package/build/umd/index.development.js +882 -696
- 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 +28 -550
- package/src/features/Cells.ts +156 -0
- package/src/features/ColumnSizing.ts +103 -51
- package/src/features/Columns.ts +290 -0
- package/src/features/Expanding.ts +7 -3
- package/src/features/Filters.ts +11 -3
- package/src/features/Grouping.ts +3 -2
- package/src/features/Headers.ts +48 -138
- package/src/features/Ordering.ts +1 -1
- package/src/features/Pagination.ts +6 -2
- package/src/features/Pinning.ts +194 -3
- package/src/features/RowSelection.ts +1 -1
- package/src/features/Rows.ts +151 -0
- package/src/features/Sorting.ts +3 -2
- package/src/features/Visibility.ts +67 -20
- package/src/types.ts +25 -37
- package/src/utils.ts +1 -3
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
Row,
|
|
9
9
|
Updater,
|
|
10
10
|
} from '../types'
|
|
11
|
-
import {
|
|
11
|
+
import { makeStateUpdater, propGetter } from '../utils'
|
|
12
12
|
|
|
13
13
|
export type ExpandedStateList = Record<string, boolean>
|
|
14
14
|
export type ExpandedState = true | Record<string, boolean>
|
|
@@ -26,6 +26,7 @@ export type ExpandedRow = {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export type ExpandedOptions<TGenerics extends TableGenerics> = {
|
|
29
|
+
manualExpanding?: boolean
|
|
29
30
|
onExpandedChange?: OnChangeFn<ExpandedState>
|
|
30
31
|
autoResetExpanded?: boolean
|
|
31
32
|
enableExpanded?: boolean
|
|
@@ -88,7 +89,7 @@ export const Expanding = {
|
|
|
88
89
|
}
|
|
89
90
|
},
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
92
93
|
instance: TableInstance<TGenerics>
|
|
93
94
|
): ExpandedInstance<TGenerics> => {
|
|
94
95
|
let registered = false
|
|
@@ -281,7 +282,10 @@ export const Expanding = {
|
|
|
281
282
|
instance.options.getExpandedRowModel(instance)
|
|
282
283
|
}
|
|
283
284
|
|
|
284
|
-
if (
|
|
285
|
+
if (
|
|
286
|
+
instance.options.manualExpanding ||
|
|
287
|
+
!instance._getExpandedRowModel
|
|
288
|
+
) {
|
|
285
289
|
return instance.getPreExpandedRowModel()
|
|
286
290
|
}
|
|
287
291
|
|
package/src/features/Filters.ts
CHANGED
|
@@ -83,6 +83,7 @@ export type FiltersOptions<TGenerics extends TableGenerics> = {
|
|
|
83
83
|
filterFns?: TGenerics['FilterFns']
|
|
84
84
|
enableFilters?: boolean
|
|
85
85
|
// Column
|
|
86
|
+
manualColumnFiltering?: boolean
|
|
86
87
|
onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>
|
|
87
88
|
autoResetColumnFilters?: boolean
|
|
88
89
|
enableColumnFilters?: boolean
|
|
@@ -90,6 +91,7 @@ export type FiltersOptions<TGenerics extends TableGenerics> = {
|
|
|
90
91
|
instance: TableInstance<TGenerics>
|
|
91
92
|
) => () => RowModel<TGenerics>
|
|
92
93
|
// Global
|
|
94
|
+
manualGlobalFiltering?: boolean
|
|
93
95
|
globalFilterFn?: FilterFnOption<TGenerics>
|
|
94
96
|
onGlobalFilterChange?: OnChangeFn<any>
|
|
95
97
|
autoResetGlobalFilter?: boolean
|
|
@@ -230,7 +232,7 @@ export const Filters = {
|
|
|
230
232
|
}
|
|
231
233
|
},
|
|
232
234
|
|
|
233
|
-
|
|
235
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
234
236
|
instance: TableInstance<TGenerics>
|
|
235
237
|
): FiltersInstance<TGenerics> => {
|
|
236
238
|
let registered = false
|
|
@@ -471,7 +473,10 @@ export const Filters = {
|
|
|
471
473
|
instance.options.getColumnFilteredRowModel(instance)
|
|
472
474
|
}
|
|
473
475
|
|
|
474
|
-
if (
|
|
476
|
+
if (
|
|
477
|
+
instance.options.manualColumnFiltering ||
|
|
478
|
+
!instance._getColumnFilteredRowModel
|
|
479
|
+
) {
|
|
475
480
|
return instance.getPreColumnFilteredRowModel()
|
|
476
481
|
}
|
|
477
482
|
|
|
@@ -487,7 +492,10 @@ export const Filters = {
|
|
|
487
492
|
instance.options.getGlobalFilteredRowModel(instance)
|
|
488
493
|
}
|
|
489
494
|
|
|
490
|
-
if (
|
|
495
|
+
if (
|
|
496
|
+
instance.options.manualGlobalFiltering ||
|
|
497
|
+
!instance._getGlobalFilteredRowModel
|
|
498
|
+
) {
|
|
491
499
|
return instance.getPreGlobalFilteredRowModel()
|
|
492
500
|
}
|
|
493
501
|
|
package/src/features/Grouping.ts
CHANGED
|
@@ -93,6 +93,7 @@ export type ColumnDefaultOptions = {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
export type GroupingOptions<TGenerics extends TableGenerics> = {
|
|
96
|
+
manualGrouping?: boolean
|
|
96
97
|
aggregationFns?: TGenerics['AggregationFns']
|
|
97
98
|
onGroupingChange?: OnChangeFn<GroupingState>
|
|
98
99
|
autoResetGrouping?: boolean
|
|
@@ -178,7 +179,7 @@ export const Grouping = {
|
|
|
178
179
|
}
|
|
179
180
|
},
|
|
180
181
|
|
|
181
|
-
|
|
182
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
182
183
|
instance: TableInstance<TGenerics>
|
|
183
184
|
): GroupingInstance<TGenerics> => {
|
|
184
185
|
let registered = false
|
|
@@ -306,7 +307,7 @@ export const Grouping = {
|
|
|
306
307
|
instance.options.getGroupedRowModel(instance)
|
|
307
308
|
}
|
|
308
309
|
|
|
309
|
-
if (!instance._getGroupedRowModel) {
|
|
310
|
+
if (instance.options.manualGrouping || !instance._getGroupedRowModel) {
|
|
310
311
|
return instance.getPreGroupedRowModel()
|
|
311
312
|
}
|
|
312
313
|
|
package/src/features/Headers.ts
CHANGED
|
@@ -15,15 +15,6 @@ import {
|
|
|
15
15
|
Row,
|
|
16
16
|
} from '../types'
|
|
17
17
|
import { propGetter, memo } from '../utils'
|
|
18
|
-
import { ColumnSizing } from './ColumnSizing'
|
|
19
|
-
|
|
20
|
-
export type HeadersRow<TGenerics extends TableGenerics> = {
|
|
21
|
-
_getAllVisibleCells: () => Cell<TGenerics>[]
|
|
22
|
-
getVisibleCells: () => Cell<TGenerics>[]
|
|
23
|
-
getLeftVisibleCells: () => Cell<TGenerics>[]
|
|
24
|
-
getCenterVisibleCells: () => Cell<TGenerics>[]
|
|
25
|
-
getRightVisibleCells: () => Cell<TGenerics>[]
|
|
26
|
-
}
|
|
27
18
|
|
|
28
19
|
export type HeadersInstance<TGenerics extends TableGenerics> = {
|
|
29
20
|
createHeader: (
|
|
@@ -32,6 +23,7 @@ export type HeadersInstance<TGenerics extends TableGenerics> = {
|
|
|
32
23
|
id?: string
|
|
33
24
|
isPlaceholder?: boolean
|
|
34
25
|
placeholderId?: string
|
|
26
|
+
index: number
|
|
35
27
|
depth: number
|
|
36
28
|
}
|
|
37
29
|
) => Header<TGenerics>
|
|
@@ -73,100 +65,12 @@ export type HeadersInstance<TGenerics extends TableGenerics> = {
|
|
|
73
65
|
headerId: string,
|
|
74
66
|
userProps?: TGetter
|
|
75
67
|
) => undefined | PropGetterValue<FooterProps, TGetter>
|
|
76
|
-
getTotalWidth: () => number
|
|
77
68
|
}
|
|
78
69
|
|
|
79
70
|
//
|
|
80
71
|
|
|
81
72
|
export const Headers = {
|
|
82
|
-
|
|
83
|
-
row: Row<TGenerics>,
|
|
84
|
-
instance: TableInstance<TGenerics>
|
|
85
|
-
): HeadersRow<TGenerics> => {
|
|
86
|
-
return {
|
|
87
|
-
_getAllVisibleCells: memo(
|
|
88
|
-
() => [
|
|
89
|
-
row
|
|
90
|
-
.getAllCells()
|
|
91
|
-
.filter(cell => cell.column.getIsVisible())
|
|
92
|
-
.map(d => d.id)
|
|
93
|
-
.join('_'),
|
|
94
|
-
],
|
|
95
|
-
_ => {
|
|
96
|
-
return row.getAllCells().filter(cell => cell.column.getIsVisible())
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
key: 'row._getAllVisibleCells',
|
|
100
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
101
|
-
}
|
|
102
|
-
),
|
|
103
|
-
getVisibleCells: memo(
|
|
104
|
-
() => [
|
|
105
|
-
row.getLeftVisibleCells(),
|
|
106
|
-
row.getCenterVisibleCells(),
|
|
107
|
-
row.getRightVisibleCells(),
|
|
108
|
-
],
|
|
109
|
-
(left, center, right) => [...left, ...center, ...right],
|
|
110
|
-
{
|
|
111
|
-
key: 'row.getVisibleCells',
|
|
112
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
113
|
-
}
|
|
114
|
-
),
|
|
115
|
-
getCenterVisibleCells: memo(
|
|
116
|
-
() => [
|
|
117
|
-
row._getAllVisibleCells(),
|
|
118
|
-
instance.getState().columnPinning.left,
|
|
119
|
-
instance.getState().columnPinning.right,
|
|
120
|
-
],
|
|
121
|
-
(allCells, left, right) => {
|
|
122
|
-
const leftAndRight = [...(left ?? []), ...(right ?? [])]
|
|
123
|
-
|
|
124
|
-
return allCells.filter(d => !leftAndRight.includes(d.columnId))
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
key: 'row.getCenterVisibleCells',
|
|
128
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
129
|
-
}
|
|
130
|
-
),
|
|
131
|
-
getLeftVisibleCells: memo(
|
|
132
|
-
() => [
|
|
133
|
-
row._getAllVisibleCells(),
|
|
134
|
-
instance.getState().columnPinning.left,
|
|
135
|
-
,
|
|
136
|
-
],
|
|
137
|
-
(allCells, left) => {
|
|
138
|
-
const cells = (left ?? [])
|
|
139
|
-
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
140
|
-
.filter(Boolean)
|
|
141
|
-
|
|
142
|
-
return cells
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
key: 'row.getLeftVisibleCells',
|
|
146
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
147
|
-
}
|
|
148
|
-
),
|
|
149
|
-
getRightVisibleCells: memo(
|
|
150
|
-
() => [
|
|
151
|
-
row._getAllVisibleCells(),
|
|
152
|
-
instance.getState().columnPinning.right,
|
|
153
|
-
],
|
|
154
|
-
(allCells, right) => {
|
|
155
|
-
const cells = (right ?? [])
|
|
156
|
-
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
157
|
-
.filter(Boolean)
|
|
158
|
-
|
|
159
|
-
return cells
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
key: 'row.getRightVisibleCells',
|
|
163
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
164
|
-
}
|
|
165
|
-
),
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
getInstance: <TGenerics extends TableGenerics>(
|
|
73
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
170
74
|
instance: TableInstance<TGenerics>
|
|
171
75
|
): HeadersInstance<TGenerics> => {
|
|
172
76
|
return {
|
|
@@ -176,6 +80,7 @@ export const Headers = {
|
|
|
176
80
|
id?: string
|
|
177
81
|
isPlaceholder?: boolean
|
|
178
82
|
placeholderId?: string
|
|
83
|
+
index: number
|
|
179
84
|
depth: number
|
|
180
85
|
}
|
|
181
86
|
) => {
|
|
@@ -184,20 +89,22 @@ export const Headers = {
|
|
|
184
89
|
let header: CoreHeader<TGenerics> = {
|
|
185
90
|
id,
|
|
186
91
|
column,
|
|
92
|
+
index: options.index,
|
|
187
93
|
isPlaceholder: options.isPlaceholder,
|
|
188
94
|
placeholderId: options.placeholderId,
|
|
189
95
|
depth: options.depth,
|
|
190
96
|
subHeaders: [],
|
|
191
97
|
colSpan: 0,
|
|
192
98
|
rowSpan: 0,
|
|
193
|
-
|
|
99
|
+
headerGroup: null!,
|
|
100
|
+
getSize: () => {
|
|
194
101
|
let sum = 0
|
|
195
102
|
|
|
196
103
|
const recurse = (header: CoreHeader<TGenerics>) => {
|
|
197
104
|
if (header.subHeaders.length) {
|
|
198
105
|
header.subHeaders.forEach(recurse)
|
|
199
106
|
} else {
|
|
200
|
-
sum += header.column.
|
|
107
|
+
sum += header.column.getSize() ?? 0
|
|
201
108
|
}
|
|
202
109
|
}
|
|
203
110
|
|
|
@@ -205,6 +112,15 @@ export const Headers = {
|
|
|
205
112
|
|
|
206
113
|
return sum
|
|
207
114
|
},
|
|
115
|
+
getStart: () => {
|
|
116
|
+
if (header.index > 0) {
|
|
117
|
+
const prevSiblingHeader =
|
|
118
|
+
header.headerGroup.headers[header.index - 1]
|
|
119
|
+
return prevSiblingHeader.getStart() + prevSiblingHeader.getSize()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return 0
|
|
123
|
+
},
|
|
208
124
|
getLeafHeaders: (): Header<TGenerics>[] => {
|
|
209
125
|
const leafHeaders: CoreHeader<TGenerics>[] = []
|
|
210
126
|
|
|
@@ -241,11 +157,11 @@ export const Headers = {
|
|
|
241
157
|
: null,
|
|
242
158
|
}
|
|
243
159
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
160
|
+
instance._features.forEach(feature => {
|
|
161
|
+
Object.assign(header, feature.createHeader?.(header, instance))
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
return header as Header<TGenerics>
|
|
249
165
|
},
|
|
250
166
|
|
|
251
167
|
// Header Groups
|
|
@@ -592,16 +508,6 @@ export const Headers = {
|
|
|
592
508
|
|
|
593
509
|
return propGetter(initialProps, userProps)
|
|
594
510
|
},
|
|
595
|
-
|
|
596
|
-
getTotalWidth: () => {
|
|
597
|
-
let width = 0
|
|
598
|
-
|
|
599
|
-
instance.getVisibleLeafColumns().forEach(column => {
|
|
600
|
-
width += column.getWidth() ?? 0
|
|
601
|
-
})
|
|
602
|
-
|
|
603
|
-
return width
|
|
604
|
-
},
|
|
605
511
|
}
|
|
606
512
|
},
|
|
607
513
|
}
|
|
@@ -652,13 +558,13 @@ export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
|
652
558
|
}
|
|
653
559
|
|
|
654
560
|
// The parent columns we're going to scan next
|
|
655
|
-
const
|
|
561
|
+
const pendingParentHeaders: Header<TGenerics>[] = []
|
|
656
562
|
|
|
657
563
|
// Scan each column for parents
|
|
658
564
|
headersToGroup.forEach(headerToGroup => {
|
|
659
565
|
// What is the latest (last) parent column?
|
|
660
566
|
|
|
661
|
-
const
|
|
567
|
+
const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0]
|
|
662
568
|
|
|
663
569
|
const isLeafHeader = headerToGroup.column.depth === headerGroup.depth
|
|
664
570
|
|
|
@@ -674,41 +580,45 @@ export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
|
674
580
|
isPlaceholder = true
|
|
675
581
|
}
|
|
676
582
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
.join('_'),
|
|
681
|
-
isPlaceholder,
|
|
682
|
-
placeholderId: isPlaceholder
|
|
683
|
-
? `${parentHeaders.filter(d => d.column === column).length}`
|
|
684
|
-
: undefined,
|
|
685
|
-
depth,
|
|
686
|
-
})
|
|
687
|
-
|
|
688
|
-
if (!latestParentHeader || latestParentHeader.column !== header.column) {
|
|
689
|
-
header.subHeaders.push(headerToGroup)
|
|
690
|
-
parentHeaders.push(header)
|
|
583
|
+
if (latestPendingParentHeader?.column === column) {
|
|
584
|
+
// This column is repeated. Add it as a sub header to the next batch
|
|
585
|
+
latestPendingParentHeader.subHeaders.push(headerToGroup)
|
|
691
586
|
} else {
|
|
692
|
-
|
|
693
|
-
|
|
587
|
+
// This is a new header. Let's create it
|
|
588
|
+
const header = instance.createHeader(column, {
|
|
589
|
+
id: [headerFamily, depth, column.id, headerToGroup?.id]
|
|
590
|
+
.filter(Boolean)
|
|
591
|
+
.join('_'),
|
|
592
|
+
isPlaceholder,
|
|
593
|
+
placeholderId: isPlaceholder
|
|
594
|
+
? `${pendingParentHeaders.filter(d => d.column === column).length}`
|
|
595
|
+
: undefined,
|
|
596
|
+
depth,
|
|
597
|
+
index: pendingParentHeaders.length,
|
|
598
|
+
})
|
|
694
599
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
600
|
+
// Add the headerToGroup as a subHeader of the new header
|
|
601
|
+
header.subHeaders.push(headerToGroup)
|
|
602
|
+
// Add the new header to the pendingParentHeaders to get grouped
|
|
603
|
+
// in the next batch
|
|
604
|
+
pendingParentHeaders.push(header)
|
|
605
|
+
}
|
|
698
606
|
|
|
699
607
|
headerGroup.headers.push(headerToGroup)
|
|
608
|
+
headerToGroup.headerGroup = headerGroup
|
|
700
609
|
})
|
|
701
610
|
|
|
702
611
|
headerGroups.push(headerGroup)
|
|
703
612
|
|
|
704
613
|
if (depth > 0) {
|
|
705
|
-
createHeaderGroup(
|
|
614
|
+
createHeaderGroup(pendingParentHeaders, depth - 1)
|
|
706
615
|
}
|
|
707
616
|
}
|
|
708
617
|
|
|
709
|
-
const bottomHeaders = columnsToGroup.map(column =>
|
|
618
|
+
const bottomHeaders = columnsToGroup.map((column, index) =>
|
|
710
619
|
instance.createHeader(column, {
|
|
711
620
|
depth: maxDepth,
|
|
621
|
+
index,
|
|
712
622
|
})
|
|
713
623
|
)
|
|
714
624
|
|
package/src/features/Ordering.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type PaginationTableState = {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export type PaginationOptions<TGenerics extends TableGenerics> = {
|
|
21
|
+
manualPagination?: boolean
|
|
21
22
|
onPaginationChange?: OnChangeFn<PaginationState>
|
|
22
23
|
autoResetPageIndex?: boolean
|
|
23
24
|
getPaginationRowModel?: (
|
|
@@ -72,7 +73,7 @@ export const Pagination = {
|
|
|
72
73
|
}
|
|
73
74
|
},
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
76
77
|
instance: TableInstance<TGenerics>
|
|
77
78
|
): PaginationInstance<TGenerics> => {
|
|
78
79
|
let registered = false
|
|
@@ -218,7 +219,10 @@ export const Pagination = {
|
|
|
218
219
|
instance.options.getPaginationRowModel(instance)
|
|
219
220
|
}
|
|
220
221
|
|
|
221
|
-
if (
|
|
222
|
+
if (
|
|
223
|
+
instance.options.manualPagination ||
|
|
224
|
+
!instance._getPaginationRowModel
|
|
225
|
+
) {
|
|
222
226
|
return instance.getPrePaginationRowModel()
|
|
223
227
|
}
|
|
224
228
|
|
package/src/features/Pinning.ts
CHANGED
|
@@ -4,10 +4,12 @@ import {
|
|
|
4
4
|
TableInstance,
|
|
5
5
|
Column,
|
|
6
6
|
TableGenerics,
|
|
7
|
+
Row,
|
|
8
|
+
Cell,
|
|
7
9
|
} from '../types'
|
|
8
|
-
import { functionalUpdate, makeStateUpdater } from '../utils'
|
|
10
|
+
import { functionalUpdate, makeStateUpdater, memo } from '../utils'
|
|
9
11
|
|
|
10
|
-
type ColumnPinningPosition = false | 'left' | 'right'
|
|
12
|
+
export type ColumnPinningPosition = false | 'left' | 'right'
|
|
11
13
|
|
|
12
14
|
export type ColumnPinningState = {
|
|
13
15
|
left?: string[]
|
|
@@ -39,6 +41,18 @@ export type ColumnPinningColumn = {
|
|
|
39
41
|
pin: (position: ColumnPinningPosition) => void
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
export type ColumnPinningRow<TGenerics extends TableGenerics> = {
|
|
45
|
+
getLeftVisibleCells: () => Cell<TGenerics>[]
|
|
46
|
+
getCenterVisibleCells: () => Cell<TGenerics>[]
|
|
47
|
+
getRightVisibleCells: () => Cell<TGenerics>[]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ColumnPinningCell<TGenerics extends TableGenerics> = {
|
|
51
|
+
getLeftVisibleCells: () => Cell<TGenerics>[]
|
|
52
|
+
getCenterVisibleCells: () => Cell<TGenerics>[]
|
|
53
|
+
getRightVisibleCells: () => Cell<TGenerics>[]
|
|
54
|
+
}
|
|
55
|
+
|
|
42
56
|
export type ColumnPinningInstance<TGenerics extends TableGenerics> = {
|
|
43
57
|
setColumnPinning: (updater: Updater<ColumnPinningState>) => void
|
|
44
58
|
resetColumnPinning: () => void
|
|
@@ -47,6 +61,9 @@ export type ColumnPinningInstance<TGenerics extends TableGenerics> = {
|
|
|
47
61
|
getColumnIsPinned: (columnId: string) => ColumnPinningPosition
|
|
48
62
|
getColumnPinnedIndex: (columnId: string) => number
|
|
49
63
|
getIsSomeColumnsPinned: () => boolean
|
|
64
|
+
getLeftLeafColumns: () => Column<TGenerics>[]
|
|
65
|
+
getRightLeafColumns: () => Column<TGenerics>[]
|
|
66
|
+
getCenterLeafColumns: () => Column<TGenerics>[]
|
|
50
67
|
}
|
|
51
68
|
|
|
52
69
|
//
|
|
@@ -81,7 +98,129 @@ export const Pinning = {
|
|
|
81
98
|
}
|
|
82
99
|
},
|
|
83
100
|
|
|
84
|
-
|
|
101
|
+
createRow: <TGenerics extends TableGenerics>(
|
|
102
|
+
row: Row<TGenerics>,
|
|
103
|
+
instance: TableInstance<TGenerics>
|
|
104
|
+
): ColumnPinningRow<TGenerics> => {
|
|
105
|
+
return {
|
|
106
|
+
getCenterVisibleCells: memo(
|
|
107
|
+
() => [
|
|
108
|
+
row._getAllVisibleCells(),
|
|
109
|
+
instance.getState().columnPinning.left,
|
|
110
|
+
instance.getState().columnPinning.right,
|
|
111
|
+
],
|
|
112
|
+
(allCells, left, right) => {
|
|
113
|
+
const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
|
|
114
|
+
|
|
115
|
+
return allCells.filter(d => !leftAndRight.includes(d.columnId))
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
key: 'row.getCenterVisibleCells',
|
|
119
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
getLeftVisibleCells: memo(
|
|
123
|
+
() => [
|
|
124
|
+
row._getAllVisibleCells(),
|
|
125
|
+
instance.getState().columnPinning.left,
|
|
126
|
+
,
|
|
127
|
+
],
|
|
128
|
+
(allCells, left) => {
|
|
129
|
+
const cells = (left ?? [])
|
|
130
|
+
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
131
|
+
.filter(Boolean)
|
|
132
|
+
.map(d => ({ ...d, position: 'left' } as Cell<TGenerics>))
|
|
133
|
+
|
|
134
|
+
return cells
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
key: 'row.getLeftVisibleCells',
|
|
138
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
139
|
+
}
|
|
140
|
+
),
|
|
141
|
+
getRightVisibleCells: memo(
|
|
142
|
+
() => [
|
|
143
|
+
row._getAllVisibleCells(),
|
|
144
|
+
instance.getState().columnPinning.right,
|
|
145
|
+
],
|
|
146
|
+
(allCells, right) => {
|
|
147
|
+
const cells = (right ?? [])
|
|
148
|
+
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
149
|
+
.filter(Boolean)
|
|
150
|
+
.map(d => ({ ...d, position: 'left' } as Cell<TGenerics>))
|
|
151
|
+
|
|
152
|
+
return cells
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
key: 'row.getRightVisibleCells',
|
|
156
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
157
|
+
}
|
|
158
|
+
),
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
createCell: <TGenerics extends TableGenerics>(
|
|
163
|
+
cell: Cell<TGenerics>,
|
|
164
|
+
instance: TableInstance<TGenerics>
|
|
165
|
+
): ColumnPinningCell<TGenerics> => {
|
|
166
|
+
return {
|
|
167
|
+
getCenterVisibleCells: memo(
|
|
168
|
+
() => [
|
|
169
|
+
cell.row._getAllVisibleCells(),
|
|
170
|
+
instance.getState().columnPinning.left,
|
|
171
|
+
instance.getState().columnPinning.right,
|
|
172
|
+
],
|
|
173
|
+
(allCells, left, right) => {
|
|
174
|
+
const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
|
|
175
|
+
|
|
176
|
+
return allCells.filter(d => !leftAndRight.includes(d.columnId))
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
key: 'row.getCenterVisibleCells',
|
|
180
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
181
|
+
}
|
|
182
|
+
),
|
|
183
|
+
getLeftVisibleCells: memo(
|
|
184
|
+
() => [
|
|
185
|
+
cell.row._getAllVisibleCells(),
|
|
186
|
+
instance.getState().columnPinning.left,
|
|
187
|
+
,
|
|
188
|
+
],
|
|
189
|
+
(allCells, left) => {
|
|
190
|
+
const cells = (left ?? [])
|
|
191
|
+
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
192
|
+
.filter(Boolean)
|
|
193
|
+
.map(d => ({ ...d, position: 'left' } as Cell<TGenerics>))
|
|
194
|
+
|
|
195
|
+
return cells
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
key: 'row.getLeftVisibleCells',
|
|
199
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
200
|
+
}
|
|
201
|
+
),
|
|
202
|
+
getRightVisibleCells: memo(
|
|
203
|
+
() => [
|
|
204
|
+
cell.row._getAllVisibleCells(),
|
|
205
|
+
instance.getState().columnPinning.right,
|
|
206
|
+
],
|
|
207
|
+
(allCells, right) => {
|
|
208
|
+
const cells = (right ?? [])
|
|
209
|
+
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
210
|
+
.filter(Boolean)
|
|
211
|
+
.map(d => ({ ...d, position: 'left' } as Cell<TGenerics>))
|
|
212
|
+
|
|
213
|
+
return cells
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
key: 'row.getRightVisibleCells',
|
|
217
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
85
224
|
instance: TableInstance<TGenerics>
|
|
86
225
|
): ColumnPinningInstance<TGenerics> => {
|
|
87
226
|
return {
|
|
@@ -176,6 +315,58 @@ export const Pinning = {
|
|
|
176
315
|
|
|
177
316
|
return Boolean(left?.length || right?.length)
|
|
178
317
|
},
|
|
318
|
+
|
|
319
|
+
getLeftLeafColumns: memo(
|
|
320
|
+
() => [
|
|
321
|
+
instance.getAllLeafColumns(),
|
|
322
|
+
instance.getState().columnPinning.left,
|
|
323
|
+
],
|
|
324
|
+
(allColumns, left) => {
|
|
325
|
+
return (left ?? [])
|
|
326
|
+
.map(columnId => allColumns.find(column => column.id === columnId)!)
|
|
327
|
+
.filter(Boolean)
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
key: 'getLeftLeafColumns',
|
|
331
|
+
debug: () =>
|
|
332
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
333
|
+
}
|
|
334
|
+
),
|
|
335
|
+
|
|
336
|
+
getRightLeafColumns: memo(
|
|
337
|
+
() => [
|
|
338
|
+
instance.getAllLeafColumns(),
|
|
339
|
+
instance.getState().columnPinning.right,
|
|
340
|
+
],
|
|
341
|
+
(allColumns, right) => {
|
|
342
|
+
return (right ?? [])
|
|
343
|
+
.map(columnId => allColumns.find(column => column.id === columnId)!)
|
|
344
|
+
.filter(Boolean)
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
key: 'getRightLeafColumns',
|
|
348
|
+
debug: () =>
|
|
349
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
350
|
+
}
|
|
351
|
+
),
|
|
352
|
+
|
|
353
|
+
getCenterLeafColumns: memo(
|
|
354
|
+
() => [
|
|
355
|
+
instance.getAllLeafColumns(),
|
|
356
|
+
instance.getState().columnPinning.left,
|
|
357
|
+
instance.getState().columnPinning.right,
|
|
358
|
+
],
|
|
359
|
+
(allColumns, left, right) => {
|
|
360
|
+
const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
|
|
361
|
+
|
|
362
|
+
return allColumns.filter(d => !leftAndRight.includes(d.id))
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
key: 'getCenterLeafColumns',
|
|
366
|
+
debug: () =>
|
|
367
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
368
|
+
}
|
|
369
|
+
),
|
|
179
370
|
}
|
|
180
371
|
},
|
|
181
372
|
}
|
|
@@ -120,7 +120,7 @@ export const RowSelection = {
|
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
124
124
|
instance: TableInstance<TGenerics>
|
|
125
125
|
): RowSelectionInstance<TGenerics> => {
|
|
126
126
|
let registered = false
|