@tanstack/table-core 8.13.2 → 8.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/build/lib/aggregationFns.d.ts +1 -1
  2. package/build/lib/aggregationFns.js.map +1 -1
  3. package/build/lib/core/column.js +1 -1
  4. package/build/lib/core/column.js.map +1 -1
  5. package/build/lib/core/headers.d.ts +1 -2
  6. package/build/lib/core/headers.js.map +1 -1
  7. package/build/lib/core/row.js.map +1 -1
  8. package/build/lib/core/table.d.ts +7 -11
  9. package/build/lib/core/table.js +21 -13
  10. package/build/lib/core/table.js.map +1 -1
  11. package/build/lib/features/ColumnFaceting.d.ts +34 -0
  12. package/build/lib/features/ColumnFaceting.js +42 -0
  13. package/build/lib/features/ColumnFaceting.js.map +1 -0
  14. package/build/lib/features/{Filters.d.ts → ColumnFiltering.d.ts} +29 -132
  15. package/build/lib/features/{Filters.js → ColumnFiltering.js} +8 -83
  16. package/build/lib/features/ColumnFiltering.js.map +1 -0
  17. package/build/lib/features/{Grouping.d.ts → ColumnGrouping.d.ts} +2 -3
  18. package/build/lib/features/{Grouping.js → ColumnGrouping.js} +3 -3
  19. package/build/lib/features/ColumnGrouping.js.map +1 -0
  20. package/build/lib/features/{Ordering.d.ts → ColumnOrdering.d.ts} +2 -3
  21. package/build/lib/features/{Ordering.js → ColumnOrdering.js} +9 -9
  22. package/build/lib/features/ColumnOrdering.js.map +1 -0
  23. package/build/lib/features/ColumnPinning.d.ts +126 -0
  24. package/build/lib/features/{Pinning.js → ColumnPinning.js} +4 -115
  25. package/build/lib/features/ColumnPinning.js.map +1 -0
  26. package/build/lib/features/ColumnSizing.d.ts +2 -3
  27. package/build/lib/features/ColumnSizing.js +3 -3
  28. package/build/lib/features/ColumnSizing.js.map +1 -1
  29. package/build/lib/features/{Visibility.d.ts → ColumnVisibility.d.ts} +2 -3
  30. package/build/lib/features/{Visibility.js → ColumnVisibility.js} +3 -3
  31. package/build/lib/features/ColumnVisibility.js.map +1 -0
  32. package/build/lib/features/GlobalFiltering.d.ts +100 -0
  33. package/build/lib/features/GlobalFiltering.js +85 -0
  34. package/build/lib/features/GlobalFiltering.js.map +1 -0
  35. package/build/lib/features/{Expanding.d.ts → RowExpanding.d.ts} +2 -3
  36. package/build/lib/features/{Expanding.js → RowExpanding.js} +3 -3
  37. package/build/lib/features/RowExpanding.js.map +1 -0
  38. package/build/lib/features/{Pagination.d.ts → RowPagination.d.ts} +2 -3
  39. package/build/lib/features/{Pagination.js → RowPagination.js} +3 -3
  40. package/build/lib/features/RowPagination.js.map +1 -0
  41. package/build/lib/features/RowPinning.d.ts +98 -0
  42. package/build/lib/features/RowPinning.js +145 -0
  43. package/build/lib/features/RowPinning.js.map +1 -0
  44. package/build/lib/features/RowSelection.d.ts +1 -2
  45. package/build/lib/features/RowSelection.js.map +1 -1
  46. package/build/lib/features/{Sorting.d.ts → RowSorting.d.ts} +5 -3
  47. package/build/lib/features/{Sorting.js → RowSorting.js} +3 -3
  48. package/build/lib/features/RowSorting.js.map +1 -0
  49. package/build/lib/filterFns.d.ts +1 -1
  50. package/build/lib/filterFns.js.map +1 -1
  51. package/build/lib/index.d.ts +21 -18
  52. package/build/lib/index.esm.js +1490 -1446
  53. package/build/lib/index.esm.js.map +1 -1
  54. package/build/lib/index.js +47 -41
  55. package/build/lib/index.js.map +1 -1
  56. package/build/lib/index.mjs +1490 -1446
  57. package/build/lib/index.mjs.map +1 -1
  58. package/build/lib/sortingFns.d.ts +1 -1
  59. package/build/lib/sortingFns.js.map +1 -1
  60. package/build/lib/types.d.ts +30 -16
  61. package/build/lib/utils/getFilteredRowModel.js.map +1 -1
  62. package/build/lib/utils/getSortedRowModel.js.map +1 -1
  63. package/build/umd/index.development.js +1500 -1453
  64. package/build/umd/index.development.js.map +1 -1
  65. package/build/umd/index.production.js +1 -1
  66. package/build/umd/index.production.js.map +1 -1
  67. package/package.json +1 -1
  68. package/src/aggregationFns.ts +1 -1
  69. package/src/core/column.ts +2 -2
  70. package/src/core/headers.ts +9 -3
  71. package/src/core/row.ts +1 -1
  72. package/src/core/table.ts +40 -32
  73. package/src/features/ColumnFaceting.ts +84 -0
  74. package/src/features/{Filters.ts → ColumnFiltering.ts} +44 -279
  75. package/src/features/{Grouping.ts → ColumnGrouping.ts} +6 -6
  76. package/src/features/{Ordering.ts → ColumnOrdering.ts} +11 -5
  77. package/src/features/ColumnPinning.ts +336 -0
  78. package/src/features/ColumnSizing.ts +10 -3
  79. package/src/features/{Visibility.ts → ColumnVisibility.ts} +2 -2
  80. package/src/features/GlobalFiltering.ts +218 -0
  81. package/src/features/{Expanding.ts → RowExpanding.ts} +9 -3
  82. package/src/features/{Pagination.ts → RowPagination.ts} +9 -3
  83. package/src/features/RowPinning.ts +273 -0
  84. package/src/features/RowSelection.ts +9 -2
  85. package/src/features/{Sorting.ts → RowSorting.ts} +5 -2
  86. package/src/filterFns.ts +1 -1
  87. package/src/index.ts +30 -18
  88. package/src/sortingFns.ts +1 -1
  89. package/src/types.ts +60 -23
  90. package/src/utils/getFilteredRowModel.ts +1 -1
  91. package/src/utils/getSortedRowModel.ts +1 -1
  92. package/build/lib/features/Expanding.js.map +0 -1
  93. package/build/lib/features/Filters.js.map +0 -1
  94. package/build/lib/features/Grouping.js.map +0 -1
  95. package/build/lib/features/Ordering.js.map +0 -1
  96. package/build/lib/features/Pagination.js.map +0 -1
  97. package/build/lib/features/Pinning.d.ts +0 -222
  98. package/build/lib/features/Pinning.js.map +0 -1
  99. package/build/lib/features/Sorting.js.map +0 -1
  100. package/build/lib/features/Visibility.js.map +0 -1
  101. package/src/features/Pinning.ts +0 -573
@@ -1,573 +0,0 @@
1
- import { TableFeature } from '../core/table'
2
- import {
3
- OnChangeFn,
4
- Updater,
5
- Table,
6
- Column,
7
- Row,
8
- Cell,
9
- RowData,
10
- } from '../types'
11
- import { getMemoOptions, makeStateUpdater, memo } from '../utils'
12
-
13
- export type ColumnPinningPosition = false | 'left' | 'right'
14
- export type RowPinningPosition = false | 'top' | 'bottom'
15
-
16
- export interface ColumnPinningState {
17
- left?: string[]
18
- right?: string[]
19
- }
20
-
21
- export interface RowPinningState {
22
- bottom?: string[]
23
- top?: string[]
24
- }
25
-
26
- export interface ColumnPinningTableState {
27
- columnPinning: ColumnPinningState
28
- }
29
-
30
- export interface RowPinningTableState {
31
- rowPinning: RowPinningState
32
- }
33
-
34
- export interface ColumnPinningOptions {
35
- /**
36
- * Enables/disables column pinning for the table. Defaults to `true`.
37
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#enablecolumnpinning)
38
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
39
- */
40
- enableColumnPinning?: boolean
41
- /**
42
- * Enables/disables all pinning for the table. Defaults to `true`.
43
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#enablepinning)
44
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
45
- */
46
- enablePinning?: boolean
47
- /**
48
- * If provided, this function will be called with an `updaterFn` when `state.columnPinning` changes. This overrides the default internal state management, so you will also need to supply `state.columnPinning` from your own managed state.
49
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#oncolumnpinningchange)
50
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/oncolumnpinningchange)
51
- */
52
- onColumnPinningChange?: OnChangeFn<ColumnPinningState>
53
- }
54
-
55
- export interface RowPinningOptions<TData extends RowData> {
56
- /**
57
- * Enables/disables row pinning for the table. Defaults to `true`.
58
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#enablerowpinning)
59
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
60
- */
61
- enableRowPinning?: boolean | ((row: Row<TData>) => boolean)
62
- /**
63
- * When `false`, pinned rows will not be visible if they are filtered or paginated out of the table. When `true`, pinned rows will always be visible regardless of filtering or pagination. Defaults to `true`.
64
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#keeppinnedrows)
65
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
66
- */
67
- keepPinnedRows?: boolean
68
- /**
69
- * If provided, this function will be called with an `updaterFn` when `state.rowPinning` changes. This overrides the default internal state management, so you will also need to supply `state.rowPinning` from your own managed state.
70
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#onrowpinningchange)
71
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/onrowpinningchange)
72
- */
73
- onRowPinningChange?: OnChangeFn<RowPinningState>
74
- }
75
-
76
- export interface ColumnPinningDefaultOptions {
77
- onColumnPinningChange: OnChangeFn<ColumnPinningState>
78
- }
79
-
80
- export interface RowPinningDefaultOptions {
81
- onRowPinningChange: OnChangeFn<RowPinningState>
82
- }
83
-
84
- export interface ColumnPinningColumnDef {
85
- /**
86
- * Enables/disables column pinning for this column. Defaults to `true`.
87
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#enablepinning-1)
88
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
89
- */
90
- enablePinning?: boolean
91
- }
92
-
93
- export interface ColumnPinningColumn {
94
- /**
95
- * Returns whether or not the column can be pinned.
96
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getcanpin)
97
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
98
- */
99
- getCanPin: () => boolean
100
- /**
101
- * Returns the pinned position of the column. (`'left'`, `'right'` or `false`)
102
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getispinned)
103
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
104
- */
105
- getIsPinned: () => ColumnPinningPosition
106
- /**
107
- * Returns the numeric pinned index of the column within a pinned column group.
108
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getpinnedindex)
109
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
110
- */
111
- getPinnedIndex: () => number
112
- /**
113
- * Pins a column to the `'left'` or `'right'`, or unpins the column to the center if `false` is passed.
114
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#pin)
115
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
116
- */
117
- pin: (position: ColumnPinningPosition) => void
118
- }
119
-
120
- export interface ColumnPinningRow<TData extends RowData> {
121
- /**
122
- * Returns all center pinned (unpinned) leaf cells in the row.
123
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getcentervisiblecells)
124
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
125
- */
126
- getCenterVisibleCells: () => Cell<TData, unknown>[]
127
- /**
128
- * Returns all left pinned leaf cells in the row.
129
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getleftvisiblecells)
130
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
131
- */
132
- getLeftVisibleCells: () => Cell<TData, unknown>[]
133
- /**
134
- * Returns all right pinned leaf cells in the row.
135
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getrightvisiblecells)
136
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
137
- */
138
- getRightVisibleCells: () => Cell<TData, unknown>[]
139
- }
140
-
141
- export interface RowPinningRow {
142
- /**
143
- * Returns whether or not the row can be pinned.
144
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getcanpin-1)
145
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
146
- */
147
- getCanPin: () => boolean
148
- /**
149
- * Returns the pinned position of the row. (`'top'`, `'bottom'` or `false`)
150
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getispinned-1)
151
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
152
- */
153
- getIsPinned: () => RowPinningPosition
154
- /**
155
- * Returns the numeric pinned index of the row within a pinned row group.
156
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getpinnedindex-1)
157
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
158
- */
159
- getPinnedIndex: () => number
160
- /**
161
- * Pins a row to the `'top'` or `'bottom'`, or unpins the row to the center if `false` is passed.
162
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#pin-1)
163
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
164
- */
165
- pin: (
166
- position: RowPinningPosition,
167
- includeLeafRows?: boolean,
168
- includeParentRows?: boolean
169
- ) => void
170
- }
171
-
172
- export interface ColumnPinningInstance<TData extends RowData> {
173
- /**
174
- * Returns all center pinned (unpinned) leaf columns.
175
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getcenterleafcolumns)
176
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
177
- */
178
- getCenterLeafColumns: () => Column<TData, unknown>[]
179
- /**
180
- * Returns whether or not any columns are pinned. Optionally specify to only check for pinned columns in either the `left` or `right` position.
181
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getissomecolumnspinned)
182
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
183
- */
184
- getIsSomeColumnsPinned: (position?: ColumnPinningPosition) => boolean
185
- /**
186
- * Returns all left pinned leaf columns.
187
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getleftleafcolumns)
188
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
189
- */
190
- getLeftLeafColumns: () => Column<TData, unknown>[]
191
- /**
192
- * Returns all right pinned leaf columns.
193
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getrightleafcolumns)
194
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
195
- */
196
- getRightLeafColumns: () => Column<TData, unknown>[]
197
- /**
198
- * Resets the **columnPinning** state to `initialState.columnPinning`, or `true` can be passed to force a default blank state reset to `{ left: [], right: [], }`.
199
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#resetcolumnpinning)
200
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
201
- */
202
- resetColumnPinning: (defaultState?: boolean) => void
203
- /**
204
- * Sets or updates the `state.columnPinning` state.
205
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#setcolumnpinning)
206
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
207
- */
208
- setColumnPinning: (updater: Updater<ColumnPinningState>) => void
209
- }
210
-
211
- export interface RowPinningInstance<TData extends RowData> {
212
- _getPinnedRows: (position: 'top' | 'bottom') => Row<TData>[]
213
- /**
214
- * Returns all bottom pinned rows.
215
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getbottomrows)
216
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
217
- */
218
- getBottomRows: () => Row<TData>[]
219
- /**
220
- * Returns all rows that are not pinned to the top or bottom.
221
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getcenterrows)
222
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
223
- */
224
- getCenterRows: () => Row<TData>[]
225
- /**
226
- * Returns whether or not any rows are pinned. Optionally specify to only check for pinned rows in either the `top` or `bottom` position.
227
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#getissomerowspinned)
228
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
229
- */
230
- getIsSomeRowsPinned: (position?: RowPinningPosition) => boolean
231
- /**
232
- * Returns all top pinned rows.
233
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#gettoprows)
234
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
235
- */
236
- getTopRows: () => Row<TData>[]
237
- /**
238
- * Resets the **rowPinning** state to `initialState.rowPinning`, or `true` can be passed to force a default blank state reset to `{ top: [], bottom: [], }`.
239
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#resetrowpinning)
240
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
241
- */
242
- resetRowPinning: (defaultState?: boolean) => void
243
- /**
244
- * Sets or updates the `state.rowPinning` state.
245
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pinning#setrowpinning)
246
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pinning)
247
- */
248
- setRowPinning: (updater: Updater<RowPinningState>) => void
249
- }
250
-
251
- //
252
-
253
- const getDefaultColumnPinningState = (): ColumnPinningState => ({
254
- left: [],
255
- right: [],
256
- })
257
-
258
- const getDefaultRowPinningState = (): RowPinningState => ({
259
- top: [],
260
- bottom: [],
261
- })
262
-
263
- export const Pinning: TableFeature = {
264
- getInitialState: (state): ColumnPinningTableState & RowPinningState => {
265
- return {
266
- columnPinning: getDefaultColumnPinningState(),
267
- rowPinning: getDefaultRowPinningState(),
268
- ...state,
269
- }
270
- },
271
-
272
- getDefaultOptions: <TData extends RowData>(
273
- table: Table<TData>
274
- ): ColumnPinningDefaultOptions & RowPinningDefaultOptions => {
275
- return {
276
- onColumnPinningChange: makeStateUpdater('columnPinning', table),
277
- onRowPinningChange: makeStateUpdater('rowPinning', table),
278
- }
279
- },
280
-
281
- createColumn: <TData extends RowData, TValue>(
282
- column: Column<TData, TValue>,
283
- table: Table<TData>
284
- ): void => {
285
- column.pin = position => {
286
- const columnIds = column
287
- .getLeafColumns()
288
- .map(d => d.id)
289
- .filter(Boolean) as string[]
290
-
291
- table.setColumnPinning(old => {
292
- if (position === 'right') {
293
- return {
294
- left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
295
- right: [
296
- ...(old?.right ?? []).filter(d => !columnIds?.includes(d)),
297
- ...columnIds,
298
- ],
299
- }
300
- }
301
-
302
- if (position === 'left') {
303
- return {
304
- left: [
305
- ...(old?.left ?? []).filter(d => !columnIds?.includes(d)),
306
- ...columnIds,
307
- ],
308
- right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
309
- }
310
- }
311
-
312
- return {
313
- left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
314
- right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
315
- }
316
- })
317
- }
318
-
319
- column.getCanPin = () => {
320
- const leafColumns = column.getLeafColumns()
321
-
322
- return leafColumns.some(
323
- d =>
324
- (d.columnDef.enablePinning ?? true) &&
325
- (table.options.enableColumnPinning ??
326
- table.options.enablePinning ??
327
- true)
328
- )
329
- }
330
-
331
- column.getIsPinned = () => {
332
- const leafColumnIds = column.getLeafColumns().map(d => d.id)
333
-
334
- const { left, right } = table.getState().columnPinning
335
-
336
- const isLeft = leafColumnIds.some(d => left?.includes(d))
337
- const isRight = leafColumnIds.some(d => right?.includes(d))
338
-
339
- return isLeft ? 'left' : isRight ? 'right' : false
340
- }
341
-
342
- column.getPinnedIndex = () => {
343
- const position = column.getIsPinned()
344
-
345
- return position
346
- ? table.getState().columnPinning?.[position]?.indexOf(column.id) ?? -1
347
- : 0
348
- }
349
- },
350
-
351
- createRow: <TData extends RowData>(
352
- row: Row<TData>,
353
- table: Table<TData>
354
- ): void => {
355
- row.pin = (position, includeLeafRows, includeParentRows) => {
356
- const leafRowIds = includeLeafRows
357
- ? row.getLeafRows().map(({ id }) => id)
358
- : []
359
- const parentRowIds = includeParentRows
360
- ? row.getParentRows().map(({ id }) => id)
361
- : []
362
- const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds])
363
-
364
- table.setRowPinning(old => {
365
- if (position === 'bottom') {
366
- return {
367
- top: (old?.top ?? []).filter(d => !rowIds?.has(d)),
368
- bottom: [
369
- ...(old?.bottom ?? []).filter(d => !rowIds?.has(d)),
370
- ...Array.from(rowIds),
371
- ],
372
- }
373
- }
374
-
375
- if (position === 'top') {
376
- return {
377
- top: [
378
- ...(old?.top ?? []).filter(d => !rowIds?.has(d)),
379
- ...Array.from(rowIds),
380
- ],
381
- bottom: (old?.bottom ?? []).filter(d => !rowIds?.has(d)),
382
- }
383
- }
384
-
385
- return {
386
- top: (old?.top ?? []).filter(d => !rowIds?.has(d)),
387
- bottom: (old?.bottom ?? []).filter(d => !rowIds?.has(d)),
388
- }
389
- })
390
- }
391
- row.getCanPin = () => {
392
- const { enableRowPinning, enablePinning } = table.options
393
- if (typeof enableRowPinning === 'function') {
394
- return enableRowPinning(row)
395
- }
396
- return enableRowPinning ?? enablePinning ?? true
397
- }
398
- row.getIsPinned = () => {
399
- const rowIds = [row.id]
400
-
401
- const { top, bottom } = table.getState().rowPinning
402
-
403
- const isTop = rowIds.some(d => top?.includes(d))
404
- const isBottom = rowIds.some(d => bottom?.includes(d))
405
-
406
- return isTop ? 'top' : isBottom ? 'bottom' : false
407
- }
408
- row.getPinnedIndex = () => {
409
- const position = row.getIsPinned()
410
- if (!position) return -1
411
-
412
- const visiblePinnedRowIds = table
413
- ._getPinnedRows(position)
414
- ?.map(({ id }) => id)
415
-
416
- return visiblePinnedRowIds?.indexOf(row.id) ?? -1
417
- }
418
- row.getCenterVisibleCells = memo(
419
- () => [
420
- row._getAllVisibleCells(),
421
- table.getState().columnPinning.left,
422
- table.getState().columnPinning.right,
423
- ],
424
- (allCells, left, right) => {
425
- const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
426
-
427
- return allCells.filter(d => !leftAndRight.includes(d.column.id))
428
- },
429
- getMemoOptions(table.options, 'debugRows', 'getCenterVisibleCells')
430
- )
431
- row.getLeftVisibleCells = memo(
432
- () => [row._getAllVisibleCells(), table.getState().columnPinning.left],
433
- (allCells, left) => {
434
- const cells = (left ?? [])
435
- .map(columnId => allCells.find(cell => cell.column.id === columnId)!)
436
- .filter(Boolean)
437
- .map(d => ({ ...d, position: 'left' }) as Cell<TData, unknown>)
438
-
439
- return cells
440
- },
441
- getMemoOptions(table.options, 'debugRows', 'getLeftVisibleCells')
442
- )
443
- row.getRightVisibleCells = memo(
444
- () => [row._getAllVisibleCells(), table.getState().columnPinning.right],
445
- (allCells, right) => {
446
- const cells = (right ?? [])
447
- .map(columnId => allCells.find(cell => cell.column.id === columnId)!)
448
- .filter(Boolean)
449
- .map(d => ({ ...d, position: 'right' }) as Cell<TData, unknown>)
450
-
451
- return cells
452
- },
453
- getMemoOptions(table.options, 'debugRows', 'getRightVisibleCells')
454
- )
455
- },
456
-
457
- createTable: <TData extends RowData>(table: Table<TData>): void => {
458
- table.setColumnPinning = updater =>
459
- table.options.onColumnPinningChange?.(updater)
460
-
461
- table.resetColumnPinning = defaultState =>
462
- table.setColumnPinning(
463
- defaultState
464
- ? getDefaultColumnPinningState()
465
- : table.initialState?.columnPinning ?? getDefaultColumnPinningState()
466
- )
467
-
468
- table.getIsSomeColumnsPinned = position => {
469
- const pinningState = table.getState().columnPinning
470
-
471
- if (!position) {
472
- return Boolean(pinningState.left?.length || pinningState.right?.length)
473
- }
474
- return Boolean(pinningState[position]?.length)
475
- }
476
-
477
- table.getLeftLeafColumns = memo(
478
- () => [table.getAllLeafColumns(), table.getState().columnPinning.left],
479
- (allColumns, left) => {
480
- return (left ?? [])
481
- .map(columnId => allColumns.find(column => column.id === columnId)!)
482
- .filter(Boolean)
483
- },
484
- getMemoOptions(table.options, 'debugColumns', 'getLeftLeafColumns')
485
- )
486
-
487
- table.getRightLeafColumns = memo(
488
- () => [table.getAllLeafColumns(), table.getState().columnPinning.right],
489
- (allColumns, right) => {
490
- return (right ?? [])
491
- .map(columnId => allColumns.find(column => column.id === columnId)!)
492
- .filter(Boolean)
493
- },
494
- getMemoOptions(table.options, 'debugColumns', 'getRightLeafColumns')
495
- )
496
-
497
- table.getCenterLeafColumns = memo(
498
- () => [
499
- table.getAllLeafColumns(),
500
- table.getState().columnPinning.left,
501
- table.getState().columnPinning.right,
502
- ],
503
- (allColumns, left, right) => {
504
- const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
505
-
506
- return allColumns.filter(d => !leftAndRight.includes(d.id))
507
- },
508
- getMemoOptions(table.options, 'debugColumns', 'getCenterLeafColumns')
509
- )
510
-
511
- table.setRowPinning = updater => table.options.onRowPinningChange?.(updater)
512
-
513
- table.resetRowPinning = defaultState =>
514
- table.setRowPinning(
515
- defaultState
516
- ? getDefaultRowPinningState()
517
- : table.initialState?.rowPinning ?? getDefaultRowPinningState()
518
- )
519
-
520
- table.getIsSomeRowsPinned = position => {
521
- const pinningState = table.getState().rowPinning
522
-
523
- if (!position) {
524
- return Boolean(pinningState.top?.length || pinningState.bottom?.length)
525
- }
526
- return Boolean(pinningState[position]?.length)
527
- }
528
-
529
- table._getPinnedRows = memo(
530
- position => [
531
- table.getRowModel().rows,
532
- table.getState().rowPinning[position!],
533
- position,
534
- ],
535
- (visibleRows, pinnedRowIds, position) => {
536
- const rows =
537
- table.options.keepPinnedRows ?? true
538
- ? //get all rows that are pinned even if they would not be otherwise visible
539
- //account for expanded parent rows, but not pagination or filtering
540
- (pinnedRowIds ?? []).map(rowId => {
541
- const row = table.getRow(rowId, true)
542
- return row.getIsAllParentsExpanded() ? row : null
543
- })
544
- : //else get only visible rows that are pinned
545
- (pinnedRowIds ?? []).map(
546
- rowId => visibleRows.find(row => row.id === rowId)!
547
- )
548
-
549
- return rows
550
- .filter(Boolean)
551
- .map(d => ({ ...d, position })) as Row<TData>[]
552
- },
553
- getMemoOptions(table.options, 'debugRows', '_getPinnedRows')
554
- )
555
-
556
- table.getTopRows = () => table._getPinnedRows('top')
557
-
558
- table.getBottomRows = () => table._getPinnedRows('bottom')
559
-
560
- table.getCenterRows = memo(
561
- () => [
562
- table.getRowModel().rows,
563
- table.getState().rowPinning.top,
564
- table.getState().rowPinning.bottom,
565
- ],
566
- (allRows, top, bottom) => {
567
- const topAndBottom = new Set([...(top ?? []), ...(bottom ?? [])])
568
- return allRows.filter(d => !topAndBottom.has(d.id))
569
- },
570
- getMemoOptions(table.options, 'debugRows', 'getCenterRows')
571
- )
572
- },
573
- }