@tanstack/table-core 8.0.0-alpha.55 → 8.0.0-alpha.59
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 +18 -404
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +3 -3
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Cells.js +107 -0
- package/build/cjs/features/Cells.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +96 -54
- 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 +13 -21
- 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 +8 -11
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +79 -220
- 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 +5 -5
- 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 +16 -48
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +84 -0
- package/build/cjs/features/Rows.js.map +1 -0
- package/build/cjs/features/Sorting.js +9 -12
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +59 -38
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js +16 -0
- package/build/cjs/filterFns.js.map +1 -1
- package/build/cjs/index.js +0 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils.js +0 -16
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +866 -856
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +424 -322
- package/build/types/core.d.ts +9 -88
- package/build/types/createTable.d.ts +10 -11
- package/build/types/features/Cells.d.ts +13 -0
- package/build/types/features/ColumnSizing.d.ts +24 -30
- package/build/types/features/Columns.d.ts +54 -0
- package/build/types/features/Expanding.d.ts +6 -9
- package/build/types/features/Filters.d.ts +3 -1
- package/build/types/features/Grouping.d.ts +6 -9
- package/build/types/features/Headers.d.ts +3 -15
- package/build/types/features/Ordering.d.ts +1 -1
- package/build/types/features/Pagination.d.ts +6 -6
- package/build/types/features/Pinning.d.ts +18 -4
- package/build/types/features/RowSelection.d.ts +6 -13
- package/build/types/features/Rows.d.ts +27 -0
- package/build/types/features/Sorting.d.ts +5 -8
- package/build/types/features/Visibility.d.ts +9 -7
- package/build/types/filterFns.d.ts +5 -0
- package/build/types/types.d.ts +27 -69
- package/build/types/utils.d.ts +1 -5
- package/build/umd/index.development.js +844 -835
- 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 +55 -601
- package/src/createTable.ts +13 -17
- package/src/features/Cells.ts +130 -0
- package/src/features/ColumnSizing.ts +111 -89
- package/src/features/Columns.ts +288 -0
- package/src/features/Expanding.ts +20 -42
- package/src/features/Filters.ts +11 -3
- package/src/features/Grouping.ts +13 -39
- package/src/features/Headers.ts +49 -233
- package/src/features/Ordering.ts +1 -1
- package/src/features/Pagination.ts +14 -4
- package/src/features/Pinning.ts +194 -3
- package/src/features/RowSelection.ts +26 -88
- package/src/features/Rows.ts +123 -0
- package/src/features/Sorting.ts +20 -43
- package/src/features/Visibility.ts +82 -63
- package/src/filterFns.ts +20 -0
- package/src/types.ts +59 -133
- package/src/utils/getColumnFilteredRowModelAsync.ts +1 -5
- package/src/utils/getGlobalFilteredRowModelAsync.ts +2 -6
- package/src/utils/getSortedRowModelAsync.ts +0 -1
- package/src/utils.ts +2 -31
package/src/features/Headers.ts
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Cell,
|
|
3
2
|
Column,
|
|
4
3
|
CoreHeader,
|
|
5
|
-
FooterGroupProps,
|
|
6
|
-
FooterProps,
|
|
7
|
-
Getter,
|
|
8
4
|
Header,
|
|
9
5
|
HeaderGroup,
|
|
10
|
-
HeaderGroupProps,
|
|
11
|
-
HeaderProps,
|
|
12
6
|
TableGenerics,
|
|
13
|
-
PropGetterValue,
|
|
14
7
|
TableInstance,
|
|
15
|
-
Row,
|
|
16
8
|
} from '../types'
|
|
17
|
-
import {
|
|
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
|
-
}
|
|
9
|
+
import { memo } from '../utils'
|
|
27
10
|
|
|
28
11
|
export type HeadersInstance<TGenerics extends TableGenerics> = {
|
|
29
12
|
createHeader: (
|
|
@@ -32,6 +15,7 @@ export type HeadersInstance<TGenerics extends TableGenerics> = {
|
|
|
32
15
|
id?: string
|
|
33
16
|
isPlaceholder?: boolean
|
|
34
17
|
placeholderId?: string
|
|
18
|
+
index: number
|
|
35
19
|
depth: number
|
|
36
20
|
}
|
|
37
21
|
) => Header<TGenerics>
|
|
@@ -56,117 +40,12 @@ export type HeadersInstance<TGenerics extends TableGenerics> = {
|
|
|
56
40
|
getRightLeafHeaders: () => Header<TGenerics>[]
|
|
57
41
|
|
|
58
42
|
getHeader: (id: string) => Header<TGenerics>
|
|
59
|
-
|
|
60
|
-
getHeaderGroupProps: <TGetter extends Getter<HeaderGroupProps>>(
|
|
61
|
-
id: string,
|
|
62
|
-
userProps?: TGetter
|
|
63
|
-
) => undefined | PropGetterValue<HeaderGroupProps, TGetter>
|
|
64
|
-
getFooterGroupProps: <TGetter extends Getter<FooterGroupProps>>(
|
|
65
|
-
id: string,
|
|
66
|
-
userProps?: TGetter
|
|
67
|
-
) => undefined | PropGetterValue<FooterGroupProps, TGetter>
|
|
68
|
-
getHeaderProps: <TGetter extends Getter<HeaderProps>>(
|
|
69
|
-
headerId: string,
|
|
70
|
-
userProps?: TGetter
|
|
71
|
-
) => undefined | PropGetterValue<HeaderProps, TGetter>
|
|
72
|
-
getFooterProps: <TGetter extends Getter<FooterProps>>(
|
|
73
|
-
headerId: string,
|
|
74
|
-
userProps?: TGetter
|
|
75
|
-
) => undefined | PropGetterValue<FooterProps, TGetter>
|
|
76
|
-
getTotalWidth: () => number
|
|
77
43
|
}
|
|
78
44
|
|
|
79
45
|
//
|
|
80
46
|
|
|
81
47
|
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: string[] = [...(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>(
|
|
48
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
170
49
|
instance: TableInstance<TGenerics>
|
|
171
50
|
): HeadersInstance<TGenerics> => {
|
|
172
51
|
return {
|
|
@@ -176,6 +55,7 @@ export const Headers = {
|
|
|
176
55
|
id?: string
|
|
177
56
|
isPlaceholder?: boolean
|
|
178
57
|
placeholderId?: string
|
|
58
|
+
index: number
|
|
179
59
|
depth: number
|
|
180
60
|
}
|
|
181
61
|
) => {
|
|
@@ -184,20 +64,22 @@ export const Headers = {
|
|
|
184
64
|
let header: CoreHeader<TGenerics> = {
|
|
185
65
|
id,
|
|
186
66
|
column,
|
|
67
|
+
index: options.index,
|
|
187
68
|
isPlaceholder: options.isPlaceholder,
|
|
188
69
|
placeholderId: options.placeholderId,
|
|
189
70
|
depth: options.depth,
|
|
190
71
|
subHeaders: [],
|
|
191
72
|
colSpan: 0,
|
|
192
73
|
rowSpan: 0,
|
|
193
|
-
|
|
74
|
+
headerGroup: null!,
|
|
75
|
+
getSize: () => {
|
|
194
76
|
let sum = 0
|
|
195
77
|
|
|
196
78
|
const recurse = (header: CoreHeader<TGenerics>) => {
|
|
197
79
|
if (header.subHeaders.length) {
|
|
198
80
|
header.subHeaders.forEach(recurse)
|
|
199
81
|
} else {
|
|
200
|
-
sum += header.column.
|
|
82
|
+
sum += header.column.getSize() ?? 0
|
|
201
83
|
}
|
|
202
84
|
}
|
|
203
85
|
|
|
@@ -205,6 +87,15 @@ export const Headers = {
|
|
|
205
87
|
|
|
206
88
|
return sum
|
|
207
89
|
},
|
|
90
|
+
getStart: () => {
|
|
91
|
+
if (header.index > 0) {
|
|
92
|
+
const prevSiblingHeader =
|
|
93
|
+
header.headerGroup.headers[header.index - 1]
|
|
94
|
+
return prevSiblingHeader.getStart() + prevSiblingHeader.getSize()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return 0
|
|
98
|
+
},
|
|
208
99
|
getLeafHeaders: (): Header<TGenerics>[] => {
|
|
209
100
|
const leafHeaders: CoreHeader<TGenerics>[] = []
|
|
210
101
|
|
|
@@ -219,10 +110,6 @@ export const Headers = {
|
|
|
219
110
|
|
|
220
111
|
return leafHeaders as Header<TGenerics>[]
|
|
221
112
|
},
|
|
222
|
-
getHeaderProps: userProps =>
|
|
223
|
-
instance.getHeaderProps(header.id, userProps)!,
|
|
224
|
-
getFooterProps: userProps =>
|
|
225
|
-
instance.getFooterProps(header.id, userProps)!,
|
|
226
113
|
renderHeader: () =>
|
|
227
114
|
column.header
|
|
228
115
|
? instance.render(column.header, {
|
|
@@ -241,11 +128,11 @@ export const Headers = {
|
|
|
241
128
|
: null,
|
|
242
129
|
}
|
|
243
130
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
131
|
+
instance._features.forEach(feature => {
|
|
132
|
+
Object.assign(header, feature.createHeader?.(header, instance))
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
return header as Header<TGenerics>
|
|
249
136
|
},
|
|
250
137
|
|
|
251
138
|
// Header Groups
|
|
@@ -531,77 +418,6 @@ export const Headers = {
|
|
|
531
418
|
|
|
532
419
|
return header
|
|
533
420
|
},
|
|
534
|
-
|
|
535
|
-
getHeaderGroupProps: (id, userProps) => {
|
|
536
|
-
const headerGroup = instance.getHeaderGroups().find(d => d.id === id)
|
|
537
|
-
|
|
538
|
-
if (!headerGroup) {
|
|
539
|
-
return
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
return propGetter(
|
|
543
|
-
{
|
|
544
|
-
key: headerGroup.id,
|
|
545
|
-
role: 'row',
|
|
546
|
-
},
|
|
547
|
-
userProps
|
|
548
|
-
)
|
|
549
|
-
},
|
|
550
|
-
|
|
551
|
-
getFooterGroupProps: (id, userProps) => {
|
|
552
|
-
const headerGroup = instance.getFooterGroups().find(d => d.id === id)
|
|
553
|
-
|
|
554
|
-
if (!headerGroup) {
|
|
555
|
-
return
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
const initialProps = {
|
|
559
|
-
key: headerGroup.id,
|
|
560
|
-
role: 'row',
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
return propGetter(initialProps, userProps)
|
|
564
|
-
},
|
|
565
|
-
|
|
566
|
-
getHeaderProps: (id, userProps) => {
|
|
567
|
-
const header = instance.getHeader(id)
|
|
568
|
-
|
|
569
|
-
if (!header) {
|
|
570
|
-
throw new Error()
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
const initialProps: HeaderProps = {
|
|
574
|
-
key: header.id,
|
|
575
|
-
role: 'columnheader',
|
|
576
|
-
colSpan: header.colSpan,
|
|
577
|
-
rowSpan: header.rowSpan,
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
return propGetter(initialProps, userProps)
|
|
581
|
-
},
|
|
582
|
-
|
|
583
|
-
getFooterProps: (id, userProps) => {
|
|
584
|
-
const header = instance.getHeader(id)
|
|
585
|
-
|
|
586
|
-
const initialProps: FooterProps = {
|
|
587
|
-
key: header.id,
|
|
588
|
-
role: 'columnfooter',
|
|
589
|
-
colSpan: header.colSpan,
|
|
590
|
-
rowSpan: header.rowSpan,
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
return propGetter(initialProps, userProps)
|
|
594
|
-
},
|
|
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
421
|
}
|
|
606
422
|
},
|
|
607
423
|
}
|
|
@@ -645,20 +461,16 @@ export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
|
645
461
|
depth,
|
|
646
462
|
id: [headerFamily, `${depth}`].filter(Boolean).join('_'),
|
|
647
463
|
headers: [],
|
|
648
|
-
getHeaderGroupProps: getterValue =>
|
|
649
|
-
instance.getHeaderGroupProps(`${depth}`, getterValue)!,
|
|
650
|
-
getFooterGroupProps: getterValue =>
|
|
651
|
-
instance.getFooterGroupProps(`${depth}`, getterValue)!,
|
|
652
464
|
}
|
|
653
465
|
|
|
654
466
|
// The parent columns we're going to scan next
|
|
655
|
-
const
|
|
467
|
+
const pendingParentHeaders: Header<TGenerics>[] = []
|
|
656
468
|
|
|
657
469
|
// Scan each column for parents
|
|
658
470
|
headersToGroup.forEach(headerToGroup => {
|
|
659
471
|
// What is the latest (last) parent column?
|
|
660
472
|
|
|
661
|
-
const
|
|
473
|
+
const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0]
|
|
662
474
|
|
|
663
475
|
const isLeafHeader = headerToGroup.column.depth === headerGroup.depth
|
|
664
476
|
|
|
@@ -674,41 +486,45 @@ export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
|
674
486
|
isPlaceholder = true
|
|
675
487
|
}
|
|
676
488
|
|
|
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)
|
|
489
|
+
if (latestPendingParentHeader?.column === column) {
|
|
490
|
+
// This column is repeated. Add it as a sub header to the next batch
|
|
491
|
+
latestPendingParentHeader.subHeaders.push(headerToGroup)
|
|
691
492
|
} else {
|
|
692
|
-
|
|
693
|
-
|
|
493
|
+
// This is a new header. Let's create it
|
|
494
|
+
const header = instance.createHeader(column, {
|
|
495
|
+
id: [headerFamily, depth, column.id, headerToGroup?.id]
|
|
496
|
+
.filter(Boolean)
|
|
497
|
+
.join('_'),
|
|
498
|
+
isPlaceholder,
|
|
499
|
+
placeholderId: isPlaceholder
|
|
500
|
+
? `${pendingParentHeaders.filter(d => d.column === column).length}`
|
|
501
|
+
: undefined,
|
|
502
|
+
depth,
|
|
503
|
+
index: pendingParentHeaders.length,
|
|
504
|
+
})
|
|
694
505
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
506
|
+
// Add the headerToGroup as a subHeader of the new header
|
|
507
|
+
header.subHeaders.push(headerToGroup)
|
|
508
|
+
// Add the new header to the pendingParentHeaders to get grouped
|
|
509
|
+
// in the next batch
|
|
510
|
+
pendingParentHeaders.push(header)
|
|
511
|
+
}
|
|
698
512
|
|
|
699
513
|
headerGroup.headers.push(headerToGroup)
|
|
514
|
+
headerToGroup.headerGroup = headerGroup
|
|
700
515
|
})
|
|
701
516
|
|
|
702
517
|
headerGroups.push(headerGroup)
|
|
703
518
|
|
|
704
519
|
if (depth > 0) {
|
|
705
|
-
createHeaderGroup(
|
|
520
|
+
createHeaderGroup(pendingParentHeaders, depth - 1)
|
|
706
521
|
}
|
|
707
522
|
}
|
|
708
523
|
|
|
709
|
-
const bottomHeaders = columnsToGroup.map(column =>
|
|
524
|
+
const bottomHeaders = columnsToGroup.map((column, index) =>
|
|
710
525
|
instance.createHeader(column, {
|
|
711
526
|
depth: maxDepth,
|
|
527
|
+
index,
|
|
712
528
|
})
|
|
713
529
|
)
|
|
714
530
|
|
package/src/features/Ordering.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
TableInstance,
|
|
5
5
|
RowModel,
|
|
6
6
|
Updater,
|
|
7
|
+
TableFeature,
|
|
7
8
|
} from '../types'
|
|
8
9
|
import { functionalUpdate, makeStateUpdater, memo } from '../utils'
|
|
9
10
|
|
|
@@ -17,7 +18,12 @@ export type PaginationTableState = {
|
|
|
17
18
|
pagination: PaginationState
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
export type PaginationInitialTableState = {
|
|
22
|
+
pagination?: Partial<PaginationState>
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
export type PaginationOptions<TGenerics extends TableGenerics> = {
|
|
26
|
+
manualPagination?: boolean
|
|
21
27
|
onPaginationChange?: OnChangeFn<PaginationState>
|
|
22
28
|
autoResetPageIndex?: boolean
|
|
23
29
|
getPaginationRowModel?: (
|
|
@@ -52,13 +58,14 @@ export type PaginationInstance<TGenerics extends TableGenerics> = {
|
|
|
52
58
|
|
|
53
59
|
//
|
|
54
60
|
|
|
55
|
-
export const Pagination = {
|
|
56
|
-
getInitialState: (): PaginationTableState => {
|
|
61
|
+
export const Pagination: TableFeature = {
|
|
62
|
+
getInitialState: (initialState): PaginationTableState => {
|
|
57
63
|
return {
|
|
58
64
|
pagination: {
|
|
59
65
|
pageCount: -1,
|
|
60
66
|
pageIndex: 0,
|
|
61
67
|
pageSize: 10,
|
|
68
|
+
...initialState?.pagination,
|
|
62
69
|
},
|
|
63
70
|
}
|
|
64
71
|
},
|
|
@@ -72,7 +79,7 @@ export const Pagination = {
|
|
|
72
79
|
}
|
|
73
80
|
},
|
|
74
81
|
|
|
75
|
-
|
|
82
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
76
83
|
instance: TableInstance<TGenerics>
|
|
77
84
|
): PaginationInstance<TGenerics> => {
|
|
78
85
|
let registered = false
|
|
@@ -218,7 +225,10 @@ export const Pagination = {
|
|
|
218
225
|
instance.options.getPaginationRowModel(instance)
|
|
219
226
|
}
|
|
220
227
|
|
|
221
|
-
if (
|
|
228
|
+
if (
|
|
229
|
+
instance.options.manualPagination ||
|
|
230
|
+
!instance._getPaginationRowModel
|
|
231
|
+
) {
|
|
222
232
|
return instance.getPrePaginationRowModel()
|
|
223
233
|
}
|
|
224
234
|
|
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 {
|
|
10
|
+
import { 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
|
}
|