@tanstack/table-core 8.0.11 → 8.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/build/cjs/core/cell.js +13 -13
  2. package/build/cjs/core/cell.js.map +1 -1
  3. package/build/cjs/core/column.js +20 -21
  4. package/build/cjs/core/column.js.map +1 -1
  5. package/build/cjs/core/headers.js +63 -68
  6. package/build/cjs/core/headers.js.map +1 -1
  7. package/build/cjs/core/row.js +16 -11
  8. package/build/cjs/core/row.js.map +1 -1
  9. package/build/cjs/core/{instance.js → table.js} +46 -57
  10. package/build/cjs/core/table.js.map +1 -0
  11. package/build/cjs/features/ColumnSizing.js +36 -36
  12. package/build/cjs/features/ColumnSizing.js.map +1 -1
  13. package/build/cjs/features/Expanding.js +34 -34
  14. package/build/cjs/features/Expanding.js.map +1 -1
  15. package/build/cjs/features/Filters.js +46 -52
  16. package/build/cjs/features/Filters.js.map +1 -1
  17. package/build/cjs/features/Grouping.js +24 -49
  18. package/build/cjs/features/Grouping.js.map +1 -1
  19. package/build/cjs/features/Ordering.js +8 -8
  20. package/build/cjs/features/Ordering.js.map +1 -1
  21. package/build/cjs/features/Pagination.js +37 -37
  22. package/build/cjs/features/Pagination.js.map +1 -1
  23. package/build/cjs/features/Pinning.js +33 -33
  24. package/build/cjs/features/Pinning.js.map +1 -1
  25. package/build/cjs/features/RowSelection.js +67 -67
  26. package/build/cjs/features/RowSelection.js.map +1 -1
  27. package/build/cjs/features/Sorting.js +36 -40
  28. package/build/cjs/features/Sorting.js.map +1 -1
  29. package/build/cjs/features/Visibility.js +30 -30
  30. package/build/cjs/features/Visibility.js.map +1 -1
  31. package/build/cjs/index.js +2 -4
  32. package/build/cjs/index.js.map +1 -1
  33. package/build/cjs/utils/filterRowsUtils.js +8 -8
  34. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  35. package/build/cjs/utils/getCoreRowModel.js +8 -8
  36. package/build/cjs/utils/getCoreRowModel.js.map +1 -1
  37. package/build/cjs/utils/getExpandedRowModel.js +4 -4
  38. package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
  39. package/build/cjs/utils/getFacetedMinMaxValues.js +3 -3
  40. package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -1
  41. package/build/cjs/utils/getFacetedRowModel.js +4 -4
  42. package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
  43. package/build/cjs/utils/getFacetedUniqueValues.js +3 -3
  44. package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -1
  45. package/build/cjs/utils/getFilteredRowModel.js +8 -8
  46. package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
  47. package/build/cjs/utils/getGroupedRowModel.js +9 -9
  48. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  49. package/build/cjs/utils/getPaginationRowModel.js +4 -4
  50. package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
  51. package/build/cjs/utils/getSortedRowModel.js +7 -7
  52. package/build/cjs/utils/getSortedRowModel.js.map +1 -1
  53. package/build/cjs/utils.js +2 -2
  54. package/build/cjs/utils.js.map +1 -1
  55. package/build/esm/index.js +567 -670
  56. package/build/esm/index.js.map +1 -1
  57. package/build/stats-html.html +1 -1
  58. package/build/stats-react.json +1092 -0
  59. package/build/types/index.d.ts +759 -0
  60. package/build/umd/index.development.js +567 -671
  61. package/build/umd/index.development.js.map +1 -1
  62. package/build/umd/index.production.js +1 -1
  63. package/build/umd/index.production.js.map +1 -1
  64. package/package.json +2 -2
  65. package/src/core/cell.ts +34 -28
  66. package/src/core/column.ts +83 -72
  67. package/src/core/headers.ts +118 -149
  68. package/src/core/row.ts +31 -25
  69. package/src/core/{instance.ts → table.ts} +85 -116
  70. package/src/features/ColumnSizing.ts +45 -47
  71. package/src/features/Expanding.ts +53 -59
  72. package/src/features/Filters.ts +112 -132
  73. package/src/features/Grouping.ts +63 -112
  74. package/src/features/Ordering.ts +19 -21
  75. package/src/features/Pagination.ts +54 -55
  76. package/src/features/Pinning.ts +49 -61
  77. package/src/features/RowSelection.ts +97 -108
  78. package/src/features/Sorting.ts +57 -72
  79. package/src/features/Visibility.ts +48 -48
  80. package/src/index.ts +1 -2
  81. package/src/types.ts +64 -69
  82. package/src/utils/filterRowsUtils.ts +33 -28
  83. package/src/utils/getCoreRowModel.ts +22 -22
  84. package/src/utils/getExpandedRowModel.ts +15 -15
  85. package/src/utils/getFacetedMinMaxValues.ts +6 -6
  86. package/src/utils/getFacetedRowModel.ts +12 -12
  87. package/src/utils/getFacetedUniqueValues.ts +6 -6
  88. package/src/utils/getFilteredRowModel.ts +17 -17
  89. package/src/utils/getGroupedRowModel.ts +18 -21
  90. package/src/utils/getPaginationRowModel.ts +10 -13
  91. package/src/utils/getSortedRowModel.ts +14 -14
  92. package/src/utils.ts +8 -2
  93. package/build/cjs/core/instance.js.map +0 -1
  94. package/build/cjs/createTable.js +0 -72
  95. package/build/cjs/createTable.js.map +0 -1
  96. package/src/createTable.ts +0 -188
@@ -1,15 +1,16 @@
1
1
  import { RowModel } from '..'
2
2
  import { BuiltInAggregationFn, aggregationFns } from '../aggregationFns'
3
- import { TableFeature } from '../core/instance'
3
+ import { TableFeature } from '../core/table'
4
4
  import {
5
5
  Cell,
6
6
  Column,
7
7
  OnChangeFn,
8
- TableInstance,
8
+ Table,
9
9
  Row,
10
10
  Updater,
11
- Renderable,
11
+ ColumnDefTemplate,
12
12
  TableGenerics,
13
+ RowData,
13
14
  } from '../types'
14
15
  import { isFunction, makeStateUpdater, Overwrite } from '../utils'
15
16
 
@@ -19,46 +20,33 @@ export type GroupingTableState = {
19
20
  grouping: GroupingState
20
21
  }
21
22
 
22
- export type AggregationFn<TGenerics extends TableGenerics> = (
23
+ export type AggregationFn<TData extends RowData> = (
23
24
  columnId: string,
24
- leafRows: Row<TGenerics>[],
25
- childRows: Row<TGenerics>[]
25
+ leafRows: Row<TData>[],
26
+ childRows: Row<TData>[]
26
27
  ) => any
27
28
 
28
- export type CustomAggregationFns<TGenerics extends TableGenerics> = Record<
29
- string,
30
- AggregationFn<TGenerics>
31
- >
29
+ export type CustomAggregationFns = Record<string, AggregationFn<any>>
32
30
 
33
- export type AggregationFnOption<TGenerics extends TableGenerics> =
31
+ export type AggregationFnOption<TData extends RowData> =
34
32
  | 'auto'
35
33
  | BuiltInAggregationFn
36
- | keyof TGenerics['AggregationFns']
37
- | AggregationFn<TGenerics>
38
-
39
- export type GroupingColumnDef<TGenerics extends TableGenerics> = {
40
- aggregationFn?: AggregationFnOption<Overwrite<TGenerics, { Value: any }>>
41
- aggregatedCell?: Renderable<
42
- TGenerics,
43
- {
44
- instance: TableInstance<TGenerics>
45
- row: Row<TGenerics>
46
- column: Column<TGenerics>
47
- cell: Cell<TGenerics>
48
- getValue: () => TGenerics['Value']
49
- }
50
- >
34
+ | AggregationFn<TData>
35
+
36
+ export type GroupingColumnDef<TData extends RowData> = {
37
+ aggregationFn?: AggregationFnOption<TData>
38
+ aggregatedCell?: ColumnDefTemplate<ReturnType<Cell<TData>['getContext']>>
51
39
  enableGrouping?: boolean
52
40
  }
53
41
 
54
- export type GroupingColumn<TGenerics extends TableGenerics> = {
42
+ export type GroupingColumn<TData extends RowData> = {
55
43
  getCanGroup: () => boolean
56
44
  getIsGrouped: () => boolean
57
45
  getGroupedIndex: () => number
58
46
  toggleGrouping: () => void
59
47
  getToggleGroupingHandler: () => () => void
60
- getAutoAggregationFn: () => AggregationFn<TGenerics> | undefined
61
- getAggregationFn: () => AggregationFn<TGenerics> | undefined
48
+ getAutoAggregationFn: () => AggregationFn<TData> | undefined
49
+ getAggregationFn: () => AggregationFn<TData> | undefined
62
50
  }
63
51
 
64
52
  export type GroupingRow = {
@@ -68,11 +56,10 @@ export type GroupingRow = {
68
56
  _groupingValuesCache: Record<string, any>
69
57
  }
70
58
 
71
- export type GroupingCell<TGenerics extends TableGenerics> = {
59
+ export type GroupingCell = {
72
60
  getIsGrouped: () => boolean
73
61
  getIsPlaceholder: () => boolean
74
62
  getIsAggregated: () => boolean
75
- renderAggregatedCell: () => string | null | TGenerics['Rendered']
76
63
  }
77
64
 
78
65
  export type ColumnDefaultOptions = {
@@ -81,33 +68,30 @@ export type ColumnDefaultOptions = {
81
68
  enableGrouping: boolean
82
69
  }
83
70
 
84
- export type GroupingOptions<TGenerics extends TableGenerics> = {
71
+ export type GroupingOptions = {
85
72
  manualGrouping?: boolean
86
- aggregationFns?: TGenerics['AggregationFns']
87
73
  onGroupingChange?: OnChangeFn<GroupingState>
88
74
  enableGrouping?: boolean
89
- getGroupedRowModel?: (instance: TableInstance<any>) => () => RowModel<any>
75
+ getGroupedRowModel?: (table: Table<any>) => () => RowModel<any>
90
76
  groupedColumnMode?: false | 'reorder' | 'remove'
91
77
  }
92
78
 
93
79
  export type GroupingColumnMode = false | 'reorder' | 'remove'
94
80
 
95
- export type GroupingInstance<TGenerics extends TableGenerics> = {
81
+ export type GroupingInstance<TData extends RowData> = {
96
82
  setGrouping: (updater: Updater<GroupingState>) => void
97
83
  resetGrouping: (defaultState?: boolean) => void
98
- getPreGroupedRowModel: () => RowModel<TGenerics>
99
- getGroupedRowModel: () => RowModel<TGenerics>
100
- _getGroupedRowModel?: () => RowModel<TGenerics>
84
+ getPreGroupedRowModel: () => RowModel<TData>
85
+ getGroupedRowModel: () => RowModel<TData>
86
+ _getGroupedRowModel?: () => RowModel<TData>
101
87
  }
102
88
 
103
89
  //
104
90
 
105
91
  export const Grouping: TableFeature = {
106
- getDefaultColumnDef: <
107
- TGenerics extends TableGenerics
108
- >(): GroupingColumnDef<TGenerics> => {
92
+ getDefaultColumnDef: <TData extends RowData>(): GroupingColumnDef<TData> => {
109
93
  return {
110
- aggregatedCell: props => props.getValue()?.toString?.() ?? null,
94
+ aggregatedCell: props => (props.getValue() as any)?.toString?.() ?? null,
111
95
  aggregationFn: 'auto',
112
96
  }
113
97
  },
@@ -119,22 +103,22 @@ export const Grouping: TableFeature = {
119
103
  }
120
104
  },
121
105
 
122
- getDefaultOptions: <TGenerics extends TableGenerics>(
123
- instance: TableInstance<TGenerics>
124
- ): GroupingOptions<TGenerics> => {
106
+ getDefaultOptions: <TData extends RowData>(
107
+ table: Table<TData>
108
+ ): GroupingOptions => {
125
109
  return {
126
- onGroupingChange: makeStateUpdater('grouping', instance),
110
+ onGroupingChange: makeStateUpdater('grouping', table),
127
111
  groupedColumnMode: 'reorder',
128
112
  }
129
113
  },
130
114
 
131
- createColumn: <TGenerics extends TableGenerics>(
132
- column: Column<TGenerics>,
133
- instance: TableInstance<TGenerics>
134
- ): GroupingColumn<TGenerics> => {
115
+ createColumn: <TData extends RowData>(
116
+ column: Column<TData>,
117
+ table: Table<TData>
118
+ ): GroupingColumn<TData> => {
135
119
  return {
136
120
  toggleGrouping: () => {
137
- instance.setGrouping(old => {
121
+ table.setGrouping(old => {
138
122
  // Find any existing grouping for this column
139
123
  if (old?.includes(column.id)) {
140
124
  return old.filter(d => d !== column.id)
@@ -148,17 +132,17 @@ export const Grouping: TableFeature = {
148
132
  return (
149
133
  column.columnDef.enableGrouping ??
150
134
  true ??
151
- instance.options.enableGrouping ??
135
+ table.options.enableGrouping ??
152
136
  true ??
153
137
  !!column.accessorFn
154
138
  )
155
139
  },
156
140
 
157
141
  getIsGrouped: () => {
158
- return instance.getState().grouping?.includes(column.id)
142
+ return table.getState().grouping?.includes(column.id)
159
143
  },
160
144
 
161
- getGroupedIndex: () => instance.getState().grouping?.indexOf(column.id),
145
+ getGroupedIndex: () => table.getState().grouping?.indexOf(column.id),
162
146
 
163
147
  getToggleGroupingHandler: () => {
164
148
  const canGroup = column.getCanGroup()
@@ -169,7 +153,7 @@ export const Grouping: TableFeature = {
169
153
  }
170
154
  },
171
155
  getAutoAggregationFn: () => {
172
- const firstRow = instance.getCoreRowModel().flatRows[0]
156
+ const firstRow = table.getCoreRowModel().flatRows[0]
173
157
 
174
158
  const value = firstRow?.getValue(column.id)
175
159
 
@@ -182,8 +166,6 @@ export const Grouping: TableFeature = {
182
166
  }
183
167
  },
184
168
  getAggregationFn: () => {
185
- const userAggregationFns = instance.options.aggregationFns
186
-
187
169
  if (!column) {
188
170
  throw new Error()
189
171
  }
@@ -192,64 +174,55 @@ export const Grouping: TableFeature = {
192
174
  ? column.columnDef.aggregationFn
193
175
  : column.columnDef.aggregationFn === 'auto'
194
176
  ? column.getAutoAggregationFn()
195
- : (userAggregationFns as Record<string, any>)?.[
196
- column.columnDef.aggregationFn as string
197
- ] ??
198
- (aggregationFns[
177
+ : (aggregationFns[
199
178
  column.columnDef.aggregationFn as BuiltInAggregationFn
200
- ] as AggregationFn<TGenerics>)
179
+ ] as AggregationFn<TData>)
201
180
  },
202
181
  }
203
182
  },
204
183
 
205
- createInstance: <TGenerics extends TableGenerics>(
206
- instance: TableInstance<TGenerics>
207
- ): GroupingInstance<TGenerics> => {
184
+ createTable: <TData extends RowData>(
185
+ table: Table<TData>
186
+ ): GroupingInstance<TData> => {
208
187
  return {
209
- setGrouping: updater => instance.options.onGroupingChange?.(updater),
188
+ setGrouping: updater => table.options.onGroupingChange?.(updater),
210
189
 
211
190
  resetGrouping: defaultState => {
212
- instance.setGrouping(
213
- defaultState ? [] : instance.initialState?.grouping ?? []
191
+ table.setGrouping(
192
+ defaultState ? [] : table.initialState?.grouping ?? []
214
193
  )
215
194
  },
216
195
 
217
- getPreGroupedRowModel: () => instance.getFilteredRowModel(),
196
+ getPreGroupedRowModel: () => table.getFilteredRowModel(),
218
197
  getGroupedRowModel: () => {
219
- if (
220
- !instance._getGroupedRowModel &&
221
- instance.options.getGroupedRowModel
222
- ) {
223
- instance._getGroupedRowModel =
224
- instance.options.getGroupedRowModel(instance)
198
+ if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
199
+ table._getGroupedRowModel = table.options.getGroupedRowModel(table)
225
200
  }
226
201
 
227
- if (instance.options.manualGrouping || !instance._getGroupedRowModel) {
228
- return instance.getPreGroupedRowModel()
202
+ if (table.options.manualGrouping || !table._getGroupedRowModel) {
203
+ return table.getPreGroupedRowModel()
229
204
  }
230
205
 
231
- return instance._getGroupedRowModel()
206
+ return table._getGroupedRowModel()
232
207
  },
233
208
  }
234
209
  },
235
210
 
236
- createRow: <TGenerics extends TableGenerics>(
237
- row: Row<TGenerics>
238
- ): GroupingRow => {
211
+ createRow: <TData extends RowData>(row: Row<TData>): GroupingRow => {
239
212
  return {
240
213
  getIsGrouped: () => !!row.groupingColumnId,
241
214
  _groupingValuesCache: {},
242
215
  }
243
216
  },
244
217
 
245
- createCell: <TGenerics extends TableGenerics>(
246
- cell: Cell<TGenerics>,
247
- column: Column<TGenerics>,
248
- row: Row<TGenerics>,
249
- instance: TableInstance<TGenerics>
250
- ): GroupingCell<TGenerics> => {
218
+ createCell: <TData extends RowData>(
219
+ cell: Cell<TData>,
220
+ column: Column<TData>,
221
+ row: Row<TData>,
222
+ table: Table<TData>
223
+ ): GroupingCell => {
251
224
  const getRenderValue = () =>
252
- cell.getValue() ?? instance.options.renderFallbackValue
225
+ cell.getValue() ?? table.options.renderFallbackValue
253
226
 
254
227
  return {
255
228
  getIsGrouped: () =>
@@ -259,34 +232,12 @@ export const Grouping: TableFeature = {
259
232
  !cell.getIsGrouped() &&
260
233
  !cell.getIsPlaceholder() &&
261
234
  !!row.subRows?.length,
262
- renderAggregatedCell: () => {
263
- if (process.env.NODE_ENV === 'development') {
264
- if (!column.columnDef.aggregatedCell) {
265
- console.warn(
266
- 'A columnDef.aggregatedCell template is recommended for displaying aggregated values.'
267
- )
268
- }
269
- }
270
-
271
- const template =
272
- column.columnDef.aggregatedCell || column.columnDef.cell
273
-
274
- return template
275
- ? instance._render(template, {
276
- instance,
277
- column,
278
- row,
279
- cell,
280
- getValue: getRenderValue,
281
- })
282
- : null
283
- },
284
235
  }
285
236
  },
286
237
  }
287
238
 
288
- export function orderColumns<TGenerics extends TableGenerics>(
289
- leafColumns: Column<TGenerics>[],
239
+ export function orderColumns<TData extends RowData>(
240
+ leafColumns: Column<TData>[],
290
241
  grouping: string[],
291
242
  groupedColumnMode?: GroupingColumnMode
292
243
  ) {
@@ -1,15 +1,16 @@
1
1
  import { makeStateUpdater, memo } from '../utils'
2
2
 
3
3
  import {
4
- TableInstance,
4
+ Table,
5
5
  OnChangeFn,
6
6
  Updater,
7
7
  Column,
8
8
  TableGenerics,
9
+ RowData,
9
10
  } from '../types'
10
11
 
11
12
  import { Grouping, orderColumns } from './Grouping'
12
- import { TableFeature } from '../core/instance'
13
+ import { TableFeature } from '../core/table'
13
14
 
14
15
  export type ColumnOrderTableState = {
15
16
  columnOrder: ColumnOrderState
@@ -25,12 +26,10 @@ export type ColumnOrderDefaultOptions = {
25
26
  onColumnOrderChange: OnChangeFn<ColumnOrderState>
26
27
  }
27
28
 
28
- export type ColumnOrderInstance<TGenerics extends TableGenerics> = {
29
+ export type ColumnOrderInstance<TData extends RowData> = {
29
30
  setColumnOrder: (updater: Updater<ColumnOrderState>) => void
30
31
  resetColumnOrder: (defaultState?: boolean) => void
31
- _getOrderColumnsFn: () => (
32
- columns: Column<TGenerics>[]
33
- ) => Column<TGenerics>[]
32
+ _getOrderColumnsFn: () => (columns: Column<TData>[]) => Column<TData>[]
34
33
  }
35
34
 
36
35
  //
@@ -43,35 +42,34 @@ export const Ordering: TableFeature = {
43
42
  }
44
43
  },
45
44
 
46
- getDefaultOptions: <TGenerics extends TableGenerics>(
47
- instance: TableInstance<TGenerics>
45
+ getDefaultOptions: <TData extends RowData>(
46
+ table: Table<TData>
48
47
  ): ColumnOrderDefaultOptions => {
49
48
  return {
50
- onColumnOrderChange: makeStateUpdater('columnOrder', instance),
49
+ onColumnOrderChange: makeStateUpdater('columnOrder', table),
51
50
  }
52
51
  },
53
52
 
54
- createInstance: <TGenerics extends TableGenerics>(
55
- instance: TableInstance<TGenerics>
56
- ): ColumnOrderInstance<TGenerics> => {
53
+ createTable: <TData extends RowData>(
54
+ table: Table<TData>
55
+ ): ColumnOrderInstance<TData> => {
57
56
  return {
58
- setColumnOrder: updater =>
59
- instance.options.onColumnOrderChange?.(updater),
57
+ setColumnOrder: updater => table.options.onColumnOrderChange?.(updater),
60
58
  resetColumnOrder: defaultState => {
61
- instance.setColumnOrder(
62
- defaultState ? [] : instance.initialState.columnOrder ?? []
59
+ table.setColumnOrder(
60
+ defaultState ? [] : table.initialState.columnOrder ?? []
63
61
  )
64
62
  },
65
63
  _getOrderColumnsFn: memo(
66
64
  () => [
67
- instance.getState().columnOrder,
68
- instance.getState().grouping,
69
- instance.options.groupedColumnMode,
65
+ table.getState().columnOrder,
66
+ table.getState().grouping,
67
+ table.options.groupedColumnMode,
70
68
  ],
71
69
  (columnOrder, grouping, groupedColumnMode) => columns => {
72
70
  // Sort grouped columns to the start of the column list
73
71
  // before the headers are built
74
- let orderedColumns: Column<TGenerics>[] = []
72
+ let orderedColumns: Column<TData>[] = []
75
73
 
76
74
  // If there is no order, return the normal columns
77
75
  if (!columnOrder?.length) {
@@ -103,7 +101,7 @@ export const Ordering: TableFeature = {
103
101
  },
104
102
  {
105
103
  key: process.env.NODE_ENV === 'development' && 'getOrderColumnsFn',
106
- // debug: () => instance.options.debugAll ?? instance.options.debugTable,
104
+ // debug: () => table.options.debugAll ?? table.options.debugTable,
107
105
  }
108
106
  ),
109
107
  }
@@ -1,10 +1,11 @@
1
- import { TableFeature } from '../core/instance'
1
+ import { TableFeature } from '../core/table'
2
2
  import {
3
3
  OnChangeFn,
4
4
  TableGenerics,
5
- TableInstance,
5
+ Table,
6
6
  RowModel,
7
7
  Updater,
8
+ RowData,
8
9
  } from '../types'
9
10
  import { functionalUpdate, makeStateUpdater, memo } from '../utils'
10
11
 
@@ -21,19 +22,19 @@ export type PaginationInitialTableState = {
21
22
  pagination?: Partial<PaginationState>
22
23
  }
23
24
 
24
- export type PaginationOptions<TGenerics extends TableGenerics> = {
25
+ export type PaginationOptions = {
25
26
  pageCount?: number
26
27
  manualPagination?: boolean
27
28
  onPaginationChange?: OnChangeFn<PaginationState>
28
29
  autoResetPageIndex?: boolean
29
- getPaginationRowModel?: (instance: TableInstance<any>) => () => RowModel<any>
30
+ getPaginationRowModel?: (table: Table<any>) => () => RowModel<any>
30
31
  }
31
32
 
32
33
  export type PaginationDefaultOptions = {
33
34
  onPaginationChange: OnChangeFn<PaginationState>
34
35
  }
35
36
 
36
- export type PaginationInstance<TGenerics extends TableGenerics> = {
37
+ export type PaginationInstance<TData extends RowData> = {
37
38
  _autoResetPageIndex: () => void
38
39
  setPagination: (updater: Updater<PaginationState>) => void
39
40
  resetPagination: (defaultState?: boolean) => void
@@ -47,9 +48,9 @@ export type PaginationInstance<TGenerics extends TableGenerics> = {
47
48
  getCanNextPage: () => boolean
48
49
  previousPage: () => void
49
50
  nextPage: () => void
50
- getPrePaginationRowModel: () => RowModel<TGenerics>
51
- getPaginationRowModel: () => RowModel<TGenerics>
52
- _getPaginationRowModel?: () => RowModel<TGenerics>
51
+ getPrePaginationRowModel: () => RowModel<TData>
52
+ getPaginationRowModel: () => RowModel<TData>
53
+ _getPaginationRowModel?: () => RowModel<TData>
53
54
  getPageCount: () => number
54
55
  }
55
56
 
@@ -74,38 +75,38 @@ export const Pagination: TableFeature = {
74
75
  }
75
76
  },
76
77
 
77
- getDefaultOptions: <TGenerics extends TableGenerics>(
78
- instance: TableInstance<TGenerics>
78
+ getDefaultOptions: <TData extends RowData>(
79
+ table: Table<TData>
79
80
  ): PaginationDefaultOptions => {
80
81
  return {
81
- onPaginationChange: makeStateUpdater('pagination', instance),
82
+ onPaginationChange: makeStateUpdater('pagination', table),
82
83
  }
83
84
  },
84
85
 
85
- createInstance: <TGenerics extends TableGenerics>(
86
- instance: TableInstance<TGenerics>
87
- ): PaginationInstance<TGenerics> => {
86
+ createTable: <TData extends RowData>(
87
+ table: Table<TData>
88
+ ): PaginationInstance<TData> => {
88
89
  let registered = false
89
90
  let queued = false
90
91
 
91
92
  return {
92
93
  _autoResetPageIndex: () => {
93
94
  if (!registered) {
94
- instance._queue(() => {
95
+ table._queue(() => {
95
96
  registered = true
96
97
  })
97
98
  return
98
99
  }
99
100
 
100
101
  if (
101
- instance.options.autoResetAll ??
102
- instance.options.autoResetPageIndex ??
103
- !instance.options.manualPagination
102
+ table.options.autoResetAll ??
103
+ table.options.autoResetPageIndex ??
104
+ !table.options.manualPagination
104
105
  ) {
105
106
  if (queued) return
106
107
  queued = true
107
- instance._queue(() => {
108
- instance.resetPageIndex()
108
+ table._queue(() => {
109
+ table.resetPageIndex()
109
110
  queued = false
110
111
  })
111
112
  }
@@ -117,23 +118,24 @@ export const Pagination: TableFeature = {
117
118
  return newState
118
119
  }
119
120
 
120
- return instance.options.onPaginationChange?.(safeUpdater)
121
+ return table.options.onPaginationChange?.(safeUpdater)
121
122
  },
122
123
  resetPagination: defaultState => {
123
- instance.setPagination(
124
+ table.setPagination(
124
125
  defaultState
125
126
  ? getDefaultPaginationState()
126
- : instance.initialState.pagination ?? getDefaultPaginationState()
127
+ : table.initialState.pagination ?? getDefaultPaginationState()
127
128
  )
128
129
  },
129
130
  setPageIndex: updater => {
130
- instance.setPagination(old => {
131
+ table.setPagination(old => {
131
132
  let pageIndex = functionalUpdate(updater, old.pageIndex)
132
133
 
133
134
  const maxPageIndex =
134
- (typeof instance.options.pageCount === 'undefined' || instance.options.pageCount === -1) ?
135
- Number.MAX_SAFE_INTEGER
136
- : instance.options.pageCount - 1
135
+ typeof table.options.pageCount === 'undefined' ||
136
+ table.options.pageCount === -1
137
+ ? Number.MAX_SAFE_INTEGER
138
+ : table.options.pageCount - 1
137
139
 
138
140
  pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex)
139
141
 
@@ -144,21 +146,21 @@ export const Pagination: TableFeature = {
144
146
  })
145
147
  },
146
148
  resetPageIndex: defaultState => {
147
- instance.setPageIndex(
149
+ table.setPageIndex(
148
150
  defaultState
149
151
  ? defaultPageIndex
150
- : instance.initialState?.pagination?.pageIndex ?? defaultPageIndex
152
+ : table.initialState?.pagination?.pageIndex ?? defaultPageIndex
151
153
  )
152
154
  },
153
155
  resetPageSize: defaultState => {
154
- instance.setPageSize(
156
+ table.setPageSize(
155
157
  defaultState
156
158
  ? defaultPageSize
157
- : instance.initialState?.pagination?.pageSize ?? defaultPageSize
159
+ : table.initialState?.pagination?.pageSize ?? defaultPageSize
158
160
  )
159
161
  },
160
162
  setPageSize: updater => {
161
- instance.setPagination(old => {
163
+ table.setPagination(old => {
162
164
  const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize))
163
165
  const topRowIndex = old.pageSize * old.pageIndex!
164
166
  const pageIndex = Math.floor(topRowIndex / pageSize)
@@ -171,10 +173,10 @@ export const Pagination: TableFeature = {
171
173
  })
172
174
  },
173
175
  setPageCount: updater =>
174
- instance.setPagination(old => {
176
+ table.setPagination(old => {
175
177
  let newPageCount = functionalUpdate(
176
178
  updater,
177
- instance.options.pageCount ?? -1
179
+ table.options.pageCount ?? -1
178
180
  )
179
181
 
180
182
  if (typeof newPageCount === 'number') {
@@ -188,7 +190,7 @@ export const Pagination: TableFeature = {
188
190
  }),
189
191
 
190
192
  getPageOptions: memo(
191
- () => [instance.getPageCount()],
193
+ () => [table.getPageCount()],
192
194
  pageCount => {
193
195
  let pageOptions: number[] = []
194
196
  if (pageCount && pageCount > 0) {
@@ -198,16 +200,16 @@ export const Pagination: TableFeature = {
198
200
  },
199
201
  {
200
202
  key: process.env.NODE_ENV === 'development' && 'getPageOptions',
201
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
203
+ debug: () => table.options.debugAll ?? table.options.debugTable,
202
204
  }
203
205
  ),
204
206
 
205
- getCanPreviousPage: () => instance.getState().pagination.pageIndex > 0,
207
+ getCanPreviousPage: () => table.getState().pagination.pageIndex > 0,
206
208
 
207
209
  getCanNextPage: () => {
208
- const { pageIndex } = instance.getState().pagination
210
+ const { pageIndex } = table.getState().pagination
209
211
 
210
- const pageCount = instance.getPageCount()
212
+ const pageCount = table.getPageCount()
211
213
 
212
214
  if (pageCount === -1) {
213
215
  return true
@@ -221,41 +223,38 @@ export const Pagination: TableFeature = {
221
223
  },
222
224
 
223
225
  previousPage: () => {
224
- return instance.setPageIndex(old => old - 1)
226
+ return table.setPageIndex(old => old - 1)
225
227
  },
226
228
 
227
229
  nextPage: () => {
228
- return instance.setPageIndex(old => {
230
+ return table.setPageIndex(old => {
229
231
  return old + 1
230
232
  })
231
233
  },
232
234
 
233
- getPrePaginationRowModel: () => instance.getExpandedRowModel(),
235
+ getPrePaginationRowModel: () => table.getExpandedRowModel(),
234
236
  getPaginationRowModel: () => {
235
237
  if (
236
- !instance._getPaginationRowModel &&
237
- instance.options.getPaginationRowModel
238
+ !table._getPaginationRowModel &&
239
+ table.options.getPaginationRowModel
238
240
  ) {
239
- instance._getPaginationRowModel =
240
- instance.options.getPaginationRowModel(instance)
241
+ table._getPaginationRowModel =
242
+ table.options.getPaginationRowModel(table)
241
243
  }
242
244
 
243
- if (
244
- instance.options.manualPagination ||
245
- !instance._getPaginationRowModel
246
- ) {
247
- return instance.getPrePaginationRowModel()
245
+ if (table.options.manualPagination || !table._getPaginationRowModel) {
246
+ return table.getPrePaginationRowModel()
248
247
  }
249
248
 
250
- return instance._getPaginationRowModel()
249
+ return table._getPaginationRowModel()
251
250
  },
252
251
 
253
252
  getPageCount: () => {
254
253
  return (
255
- instance.options.pageCount ??
254
+ table.options.pageCount ??
256
255
  Math.ceil(
257
- instance.getPrePaginationRowModel().rows.length /
258
- instance.getState().pagination.pageSize
256
+ table.getPrePaginationRowModel().rows.length /
257
+ table.getState().pagination.pageSize
259
258
  )
260
259
  )
261
260
  },