@tanstack/table-core 8.0.0-alpha.27 → 8.0.0-alpha.32

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 (122) hide show
  1. package/build/cjs/aggregationTypes.js +1 -0
  2. package/build/cjs/aggregationTypes.js.map +1 -1
  3. package/build/cjs/core.js +29 -79
  4. package/build/cjs/core.js.map +1 -1
  5. package/build/cjs/createTable.js.map +1 -1
  6. package/build/cjs/features/ColumnSizing.js.map +1 -1
  7. package/build/cjs/features/Expanding.js +14 -18
  8. package/build/cjs/features/Expanding.js.map +1 -1
  9. package/build/cjs/features/Filters.js +29 -82
  10. package/build/cjs/features/Filters.js.map +1 -1
  11. package/build/cjs/features/Grouping.js +10 -16
  12. package/build/cjs/features/Grouping.js.map +1 -1
  13. package/build/cjs/features/Headers.js.map +1 -1
  14. package/build/cjs/features/Ordering.js.map +1 -1
  15. package/build/cjs/features/Pagination.js +10 -17
  16. package/build/cjs/features/Pagination.js.map +1 -1
  17. package/build/cjs/features/Pinning.js.map +1 -1
  18. package/build/cjs/features/RowSelection.js.map +1 -1
  19. package/build/cjs/features/Sorting.js +11 -17
  20. package/build/cjs/features/Sorting.js.map +1 -1
  21. package/build/cjs/features/Visibility.js.map +1 -1
  22. package/build/cjs/filterTypes.js.map +1 -1
  23. package/build/cjs/index.js +19 -12
  24. package/build/cjs/index.js.map +1 -1
  25. package/build/cjs/sortTypes.js.map +1 -1
  26. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  27. package/build/cjs/utils/getColumnFilteredRowModelSync.js +113 -0
  28. package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -0
  29. package/build/cjs/utils/getCoreRowModelAsync.js +125 -0
  30. package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -0
  31. package/build/cjs/utils/getCoreRowModelSync.js +102 -0
  32. package/build/cjs/utils/getCoreRowModelSync.js.map +1 -0
  33. package/build/cjs/utils/getExpandedRowModel.js +61 -0
  34. package/build/cjs/utils/getExpandedRowModel.js.map +1 -0
  35. package/build/cjs/utils/getGlobalFilteredRowModelSync.js +89 -0
  36. package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +1 -0
  37. package/build/cjs/utils/getGroupedRowModel.js +174 -0
  38. package/build/cjs/utils/getGroupedRowModel.js.map +1 -0
  39. package/build/cjs/utils/getPaginationRowModel.js +61 -0
  40. package/build/cjs/utils/getPaginationRowModel.js.map +1 -0
  41. package/build/cjs/utils/getSortedRowModelSync.js +116 -0
  42. package/build/cjs/utils/getSortedRowModelSync.js.map +1 -0
  43. package/build/cjs/utils.js +159 -21
  44. package/build/cjs/utils.js.map +1 -1
  45. package/build/esm/index.js +857 -505
  46. package/build/esm/index.js.map +1 -1
  47. package/build/stats-html.html +1 -1
  48. package/build/stats-react.json +406 -312
  49. package/build/types/aggregationTypes.d.ts +1 -1
  50. package/build/types/core.d.ts +9 -1
  51. package/build/types/createTable.d.ts +2 -4
  52. package/build/types/features/Expanding.d.ts +2 -1
  53. package/build/types/features/Filters.d.ts +6 -2
  54. package/build/types/features/Grouping.d.ts +3 -2
  55. package/build/types/features/Pagination.d.ts +2 -1
  56. package/build/types/features/Sorting.d.ts +2 -1
  57. package/build/types/index.d.ts +8 -6
  58. package/build/types/types.d.ts +3 -2
  59. package/build/types/utils/getColumnFilteredRowModelAsync.d.ts +4 -0
  60. package/build/types/utils/getColumnFilteredRowModelSync.d.ts +2 -0
  61. package/build/types/utils/getCoreRowModelAsync.d.ts +4 -0
  62. package/build/types/utils/getCoreRowModelSync.d.ts +2 -0
  63. package/build/types/utils/getExpandedRowModel.d.ts +7 -0
  64. package/build/types/utils/getGlobalFilteredRowModelAsync.d.ts +4 -0
  65. package/build/types/utils/getGlobalFilteredRowModelSync.d.ts +2 -0
  66. package/build/types/utils/getGroupedRowModel.d.ts +2 -0
  67. package/build/types/utils/getPaginationRowModel.d.ts +4 -0
  68. package/build/types/utils/{sortRowsQuicksortFn.d.ts → getSortedRowModelAsync.d.ts} +3 -1
  69. package/build/types/utils/getSortedRowModelSync.d.ts +2 -0
  70. package/build/types/utils.d.ts +16 -0
  71. package/build/umd/index.development.js +872 -513
  72. package/build/umd/index.development.js.map +1 -1
  73. package/build/umd/index.production.js +1 -1
  74. package/build/umd/index.production.js.map +1 -1
  75. package/package.json +1 -1
  76. package/src/aggregationTypes.ts +1 -1
  77. package/src/core.tsx +46 -99
  78. package/src/createTable.tsx +2 -6
  79. package/src/features/Expanding.ts +21 -29
  80. package/src/features/Filters.ts +53 -100
  81. package/src/features/Grouping.ts +19 -21
  82. package/src/features/Pagination.ts +19 -28
  83. package/src/features/Sorting.ts +20 -24
  84. package/src/index.tsx +8 -6
  85. package/src/types.ts +4 -1
  86. package/src/utils/getColumnFilteredRowModelAsync.ts +117 -0
  87. package/src/utils/getColumnFilteredRowModelSync.ts +97 -0
  88. package/src/utils/getCoreRowModelAsync.ts +103 -0
  89. package/src/utils/getCoreRowModelSync.ts +105 -0
  90. package/src/utils/getExpandedRowModel.ts +58 -0
  91. package/src/utils/getGlobalFilteredRowModelAsync.ts +95 -0
  92. package/src/utils/getGlobalFilteredRowModelSync.ts +74 -0
  93. package/src/utils/getGroupedRowModel.ts +187 -0
  94. package/src/utils/getPaginationRowModel.ts +45 -0
  95. package/src/utils/getSortedRowModelAsync.ts +199 -0
  96. package/src/utils/getSortedRowModelSync.ts +116 -0
  97. package/src/utils.tsx +193 -22
  98. package/build/cjs/utils/columnFilterRowsFn.js +0 -73
  99. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  100. package/build/cjs/utils/expandRowsFn.js +0 -37
  101. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  102. package/build/cjs/utils/globalFilterRowsFn.js +0 -49
  103. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  104. package/build/cjs/utils/groupRowsFn.js +0 -155
  105. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  106. package/build/cjs/utils/paginateRowsFn.js +0 -44
  107. package/build/cjs/utils/paginateRowsFn.js.map +0 -1
  108. package/build/cjs/utils/sortRowsFn.js +0 -94
  109. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  110. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  111. package/build/types/utils/expandRowsFn.d.ts +0 -2
  112. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  113. package/build/types/utils/groupRowsFn.d.ts +0 -2
  114. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  115. package/build/types/utils/sortRowsFn.d.ts +0 -2
  116. package/src/utils/columnFilterRowsFn.ts +0 -56
  117. package/src/utils/expandRowsFn.ts +0 -34
  118. package/src/utils/globalFilterRowsFn.ts +0 -39
  119. package/src/utils/groupRowsFn.ts +0 -174
  120. package/src/utils/paginateRowsFn.ts +0 -28
  121. package/src/utils/sortRowsFn.ts +0 -99
  122. package/src/utils/sortRowsQuicksortFn.ts +0 -174
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.0.0-alpha.27",
4
+ "version": "8.0.0-alpha.32",
5
5
  "description": "Hooks for building lightweight, fast and extendable datagrids for React",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/tanstack/react-table#readme",
@@ -72,7 +72,7 @@ function extent(
72
72
  return [min, max]
73
73
  }
74
74
 
75
- function mean(getLeafValues: () => unknown[]) {
75
+ export function mean(getLeafValues: () => unknown[]) {
76
76
  let count = 0
77
77
  let sum = 0
78
78
 
package/src/core.tsx CHANGED
@@ -46,6 +46,7 @@ import { RowSelection } from './features/RowSelection'
46
46
  import { Sorting } from './features/Sorting'
47
47
  import { Visibility } from './features/Visibility'
48
48
  import { Headers } from './features/Headers'
49
+ import { mean } from './aggregationTypes'
49
50
 
50
51
  const features: TableFeature[] = [
51
52
  Headers,
@@ -61,12 +62,19 @@ const features: TableFeature[] = [
61
62
  ColumnSizing,
62
63
  ]
63
64
 
65
+ export type CoreTableState = {
66
+ coreProgress: number
67
+ }
68
+
64
69
  export type CoreOptions<TGenerics extends AnyGenerics> = {
65
70
  data: TGenerics['Row'][]
66
71
  columns: ColumnDef<TGenerics>[]
67
72
  state: Partial<TableState>
68
73
  onStateChange: (updater: Updater<TableState>) => void
69
74
  render: TGenerics['Render']
75
+ getCoreRowModel: (
76
+ instance: TableInstance<TGenerics>
77
+ ) => () => RowModel<TGenerics>
70
78
  debugAll?: boolean
71
79
  debugTable?: boolean
72
80
  debugHeaders?: boolean
@@ -84,6 +92,11 @@ export type CoreOptions<TGenerics extends AnyGenerics> = {
84
92
  parent?: Row<TGenerics>
85
93
  ) => string
86
94
  autoResetAll?: boolean
95
+ mergeOptions?: (
96
+ defaultOptions: TableFeature,
97
+ options: Partial<Options<TGenerics>>
98
+ ) => Options<TGenerics>
99
+ meta?: TGenerics['TableMeta']
87
100
  }
88
101
 
89
102
  export type TableCore<TGenerics extends AnyGenerics> = {
@@ -124,6 +137,7 @@ export type TableCore<TGenerics extends AnyGenerics> = {
124
137
  values: Record<string, any>
125
138
  ) => Row<TGenerics>
126
139
  getCoreRowModel: () => RowModel<TGenerics>
140
+ _getCoreRowModel?: () => RowModel<TGenerics>
127
141
  getRowModel: () => RowModel<TGenerics>
128
142
  getRow: (id: string) => Row<TGenerics>
129
143
  getCell: (rowId: string, columnId: string) => Cell<TGenerics>
@@ -146,6 +160,7 @@ export type TableCore<TGenerics extends AnyGenerics> = {
146
160
  template: Renderable<TGenerics, TProps>,
147
161
  props: TProps
148
162
  ) => string | null | ReturnType<UseRenderer<TGenerics>>
163
+ getOverallProgress: () => number
149
164
  }
150
165
 
151
166
  export type CoreRow<TGenerics extends AnyGenerics> = {
@@ -232,7 +247,12 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
232
247
 
233
248
  instance.options = buildOptions(options)
234
249
 
250
+ const coreInitialState: CoreTableState = {
251
+ coreProgress: 1,
252
+ }
253
+
235
254
  const initialState = {
255
+ ...coreInitialState,
236
256
  ...features.reduce((obj, feature) => {
237
257
  return Object.assign(obj, feature.getInitialState?.())
238
258
  }, {}),
@@ -249,9 +269,15 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
249
269
  instance.setState(instance.initialState)
250
270
  },
251
271
  setOptions: updater => {
252
- instance.options = buildOptions(
253
- functionalUpdate(updater, instance.options)
254
- )
272
+ const newOptions = functionalUpdate(updater, instance.options)
273
+ if (instance.options.mergeOptions) {
274
+ instance.options = instance.options.mergeOptions(
275
+ defaultOptions,
276
+ newOptions
277
+ )
278
+ } else {
279
+ instance.options = buildOptions(newOptions)
280
+ }
255
281
  },
256
282
  render: (template, props) => {
257
283
  if (typeof instance.options.render === 'function') {
@@ -557,103 +583,13 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
557
583
  return row as Row<TGenerics>
558
584
  },
559
585
 
560
- getCoreRowModel: memo(
561
- () => [instance.options.data],
562
- (
563
- data
564
- ): {
565
- rows: Row<TGenerics>[]
566
- flatRows: Row<TGenerics>[]
567
- rowsById: Record<string, Row<TGenerics>>
568
- } => {
569
- // Access the row model using initial columns
570
- const rows: Row<TGenerics>[] = []
571
- const flatRows: Row<TGenerics>[] = []
572
- const rowsById: Record<string, Row<TGenerics>> = {}
573
-
574
- const leafColumns = instance.getAllLeafColumns()
575
-
576
- const accessRow = (
577
- originalRow: TGenerics['Row'],
578
- rowIndex: number,
579
- depth = 0,
580
- parentRows: Row<TGenerics>[],
581
- parent?: Row<TGenerics>
582
- ) => {
583
- const id = instance.getRowId(originalRow, rowIndex, parent)
584
-
585
- if (!id) {
586
- if (process.env.NODE_ENV !== 'production') {
587
- throw new Error(`getRowId expected an ID, but got ${id}`)
588
- }
589
- }
590
-
591
- const values: Record<string, any> = {}
592
-
593
- for (let i = 0; i < leafColumns.length; i++) {
594
- const column = leafColumns[i]
595
- if (column && column.accessorFn) {
596
- values[column.id] = column.accessorFn(originalRow, rowIndex)
597
- }
598
- }
599
-
600
- // Make the row
601
- const row = instance.createRow(
602
- id,
603
- originalRow,
604
- rowIndex,
605
- depth,
606
- values
607
- )
608
-
609
- // Push instance row into the parentRows array
610
- parentRows.push(row)
611
- // Keep track of every row in a flat array
612
- flatRows.push(row)
613
- // Also keep track of every row by its ID
614
- rowsById[id] = row
615
-
616
- // Get the original subrows
617
- if (instance.options.getSubRows) {
618
- const originalSubRows = instance.options.getSubRows(
619
- originalRow,
620
- rowIndex
621
- )
622
-
623
- // Then recursively access them
624
- if (originalSubRows?.length) {
625
- row.originalSubRows = originalSubRows
626
- const subRows: Row<TGenerics>[] = []
627
-
628
- for (let i = 0; i < row.originalSubRows.length; i++) {
629
- accessRow(
630
- row.originalSubRows[i] as TGenerics['Row'],
631
- i,
632
- depth + 1,
633
- subRows,
634
- row
635
- )
636
- }
637
- row.subRows = subRows
638
- }
639
- }
640
- }
641
-
642
- for (let i = 0; i < data.length; i++) {
643
- accessRow(data[i] as TGenerics['Row'], i, 0, rows)
644
- }
645
-
646
- return { rows, flatRows, rowsById }
647
- },
648
- {
649
- key: 'getRowModel',
650
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
651
- onChange: () => {
652
- instance._notifyFiltersReset()
653
- instance._notifyRowSelectionReset()
654
- },
586
+ getCoreRowModel: () => {
587
+ if (!instance._getCoreRowModel) {
588
+ instance._getCoreRowModel = instance.options.getCoreRowModel(instance)
655
589
  }
656
- ),
590
+
591
+ return instance._getCoreRowModel()
592
+ },
657
593
 
658
594
  // The final calls start at the bottom of the model,
659
595
  // expanded rows, which then work their way up
@@ -764,6 +700,17 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
764
700
  instance.getRightHeaderGroups()[0]?.headers.reduce((sum, header) => {
765
701
  return sum + header.getWidth()
766
702
  }, 0) ?? 0,
703
+
704
+ getOverallProgress: () => {
705
+ const { coreProgress, columnFiltersProgress, globalFilterProgress } =
706
+ instance.getState()
707
+
708
+ return mean(() =>
709
+ [coreProgress, columnFiltersProgress, globalFilterProgress].filter(
710
+ d => d < 1
711
+ )
712
+ ) as number
713
+ },
767
714
  }
768
715
 
769
716
  instance = Object.assign(instance, finalInstance)
@@ -14,13 +14,9 @@ export type CreateTableFactory<TGenerics extends AnyGenerics> = <
14
14
  TSubGenerics extends {
15
15
  Row: any
16
16
  ColumnMeta?: object
17
+ TableMeta?: object
17
18
  }
18
- >() => Table<
19
- Overwrite<
20
- TGenerics,
21
- { Row: TSubGenerics['Row']; ColumnMeta: TSubGenerics['ColumnMeta'] }
22
- >
23
- >
19
+ >() => Table<Overwrite<TGenerics, TSubGenerics>>
24
20
 
25
21
  export type CreateTableFactoryOptions<
26
22
  TRender extends AnyRender,
@@ -31,10 +31,9 @@ export type ExpandedOptions<TGenerics extends AnyGenerics> = {
31
31
  onExpandedChange?: OnChangeFn<ExpandedState>
32
32
  autoResetExpanded?: boolean
33
33
  enableExpanded?: boolean
34
- expandRowsFn?: (
35
- instance: TableInstance<TGenerics>,
36
- rowModel: RowModel<TGenerics>
37
- ) => RowModel<TGenerics>
34
+ getExpandedRowModel?: (
35
+ instance: TableInstance<TGenerics>
36
+ ) => () => RowModel<TGenerics>
38
37
  expandSubRows?: boolean
39
38
  defaultCanExpand?: boolean
40
39
  getIsRowExpanded?: (row: Row<TGenerics>) => boolean
@@ -66,6 +65,7 @@ export type ExpandedInstance<TGenerics extends AnyGenerics> = {
66
65
  getIsAllRowsExpanded: () => boolean
67
66
  getExpandedDepth: () => number
68
67
  getExpandedRowModel: () => RowModel<TGenerics>
68
+ _getExpandedRowModel?: () => RowModel<TGenerics>
69
69
  getPreExpandedRowModel: () => RowModel<TGenerics>
70
70
  }
71
71
 
@@ -96,6 +96,8 @@ export const Expanding = {
96
96
 
97
97
  return {
98
98
  _notifyExpandedReset: () => {
99
+ instance._notifyPageIndexReset()
100
+
99
101
  if (!registered) {
100
102
  registered = true
101
103
  return
@@ -211,7 +213,7 @@ export const Expanding = {
211
213
  title: canExpand ? 'Toggle Expanded' : undefined,
212
214
  onClick: canExpand
213
215
  ? (e: MouseEvent | TouchEvent) => {
214
- e.persist()
216
+ e.persist?.()
215
217
  instance.toggleRowExpanded(rowId)
216
218
  }
217
219
  : undefined,
@@ -223,7 +225,7 @@ export const Expanding = {
223
225
  const initialProps: ToggleExpandedProps = {
224
226
  title: 'Toggle All Expanded',
225
227
  onClick: (e: MouseEvent | TouchEvent) => {
226
- e.persist()
228
+ e.persist?.()
227
229
  instance.toggleAllRowsExpanded()
228
230
  },
229
231
  }
@@ -269,32 +271,22 @@ export const Expanding = {
269
271
 
270
272
  return maxDepth
271
273
  },
272
- getExpandedRowModel: memo(
273
- () => [
274
- instance.getState().expanded,
275
- instance.getGroupedRowModel(),
276
- instance.options.expandRowsFn,
277
- instance.options.paginateExpandedRows,
278
- ],
279
- (expanded, rowModel, expandRowsFn, paginateExpandedRows) => {
280
- if (
281
- !expandRowsFn ||
282
- // Do not expand if rows are not included in pagination
283
- !paginateExpandedRows ||
284
- (expanded !== true && !Object.keys(expanded ?? {}).length)
285
- ) {
286
- return rowModel
287
- }
274
+ getPreExpandedRowModel: () => instance.getGroupedRowModel(),
275
+ getExpandedRowModel: () => {
276
+ if (
277
+ !instance._getExpandedRowModel &&
278
+ instance.options.getExpandedRowModel
279
+ ) {
280
+ instance._getExpandedRowModel =
281
+ instance.options.getExpandedRowModel(instance)
282
+ }
288
283
 
289
- return expandRowsFn(instance, rowModel)
290
- },
291
- {
292
- key: 'getExpandedRowModel',
293
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
284
+ if (!instance._getExpandedRowModel) {
285
+ return instance.getPreExpandedRowModel()
294
286
  }
295
- ),
296
287
 
297
- getPreExpandedRowModel: () => instance.getGroupedRowModel(),
288
+ return instance._getExpandedRowModel()
289
+ },
298
290
  }
299
291
  },
300
292
 
@@ -42,6 +42,8 @@ export type CustomFilterTypes<TGenerics extends AnyGenerics> = Record<
42
42
  export type FiltersTableState = {
43
43
  columnFilters: ColumnFiltersState
44
44
  globalFilter: any
45
+ columnFiltersProgress: number
46
+ globalFilterProgress: number
45
47
  }
46
48
 
47
49
  export type FilterType<TGenerics extends AnyGenerics> =
@@ -81,20 +83,18 @@ export type FiltersOptions<TGenerics extends AnyGenerics> = {
81
83
  onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>
82
84
  autoResetColumnFilters?: boolean
83
85
  enableColumnFilters?: boolean
84
- columnFilterRowsFn?: (
85
- instance: TableInstance<TGenerics>,
86
- coreRowModel: RowModel<TGenerics>
87
- ) => RowModel<TGenerics>
86
+ getColumnFilteredRowModel?: (
87
+ instance: TableInstance<TGenerics>
88
+ ) => () => RowModel<TGenerics>
88
89
  // Global
89
90
  globalFilterType?: FilterType<TGenerics>
90
91
  onGlobalFilterChange?: OnChangeFn<any>
91
92
  enableGlobalFilters?: boolean
92
93
  autoResetGlobalFilter?: boolean
93
94
  enableGlobalFilter?: boolean
94
- globalFilterRowsFn?: (
95
- instance: TableInstance<TGenerics>,
96
- rowModel: RowModel<TGenerics>
97
- ) => RowModel<TGenerics>
95
+ getGlobalFilteredRowModel?: (
96
+ instance: TableInstance<TGenerics>
97
+ ) => () => RowModel<TGenerics>
98
98
  getColumnCanGlobalFilterFn?: (column: Column<TGenerics>) => boolean
99
99
  }
100
100
 
@@ -120,6 +120,7 @@ export type FiltersInstance<TGenerics extends AnyGenerics> = {
120
120
  // Column Filters
121
121
  getPreColumnFilteredRowModel: () => RowModel<TGenerics>
122
122
  getColumnFilteredRowModel: () => RowModel<TGenerics>
123
+ _getColumnFilteredRowModel?: () => RowModel<TGenerics>
123
124
 
124
125
  // Global Filters
125
126
  setGlobalFilter: (updater: Updater<any>) => void
@@ -129,6 +130,7 @@ export type FiltersInstance<TGenerics extends AnyGenerics> = {
129
130
  getColumnCanGlobalFilter: (columnId: string) => boolean
130
131
  getPreGlobalFilteredRowModel: () => RowModel<TGenerics>
131
132
  getGlobalFilteredRowModel: () => RowModel<TGenerics>
133
+ _getGlobalFilteredRowModel?: () => RowModel<TGenerics>
132
134
  }
133
135
 
134
136
  //
@@ -146,6 +148,8 @@ export const Filters = {
146
148
  return {
147
149
  columnFilters: [],
148
150
  globalFilter: undefined,
151
+ columnFiltersProgress: 1,
152
+ globalFilterProgress: 1,
149
153
  }
150
154
  },
151
155
 
@@ -235,6 +239,8 @@ export const Filters = {
235
239
 
236
240
  return {
237
241
  _notifyFiltersReset: () => {
242
+ instance._notifySortingReset()
243
+
238
244
  if (!registered) {
239
245
  registered = true
240
246
  return
@@ -244,15 +250,18 @@ export const Filters = {
244
250
  return
245
251
  }
246
252
 
247
- if (instance.options.autoResetAll === true) {
248
- instance.resetSorting()
249
- } else {
250
- if (instance.options.autoResetColumnFilters) {
251
- instance.resetColumnFilters()
252
- }
253
- if (instance.options.autoResetGlobalFilter) {
254
- instance.resetGlobalFilter()
255
- }
253
+ if (
254
+ instance.options.autoResetAll === true ||
255
+ instance.options.autoResetColumnFilters
256
+ ) {
257
+ instance.resetColumnFilters()
258
+ }
259
+
260
+ if (
261
+ instance.options.autoResetAll === true ||
262
+ instance.options.autoResetGlobalFilter
263
+ ) {
264
+ instance.resetGlobalFilter()
256
265
  }
257
266
  },
258
267
  getColumnAutoFilterFn: columnId => {
@@ -350,7 +359,7 @@ export const Filters = {
350
359
  },
351
360
 
352
361
  resetGlobalFilter: () => {
353
- instance.setGlobalFilter(undefined)
362
+ instance.setGlobalFilter(instance.initialState.globalFilter)
354
363
  },
355
364
 
356
365
  getColumnCanColumnFilter: columnId => {
@@ -462,93 +471,37 @@ export const Filters = {
462
471
 
463
472
  getPreFilteredRowModel: () => instance.getCoreRowModel(),
464
473
  getPreColumnFilteredRowModel: () => instance.getCoreRowModel(),
465
- getColumnFilteredRowModel: memo(
466
- () => [
467
- instance.getState().columnFilters,
468
- instance.getCoreRowModel(),
469
- instance.options.columnFilterRowsFn,
470
- ],
471
- (columnFilters, rowModel, columnFiltersFn) => {
472
- const columnFilteredRowModel = (() => {
473
- if (!columnFilters?.length || !columnFiltersFn) {
474
- return rowModel
475
- }
476
-
477
- return columnFiltersFn(instance as any, rowModel)
478
- })()
479
-
480
- // Now that each filtered column has it's partially filtered rows,
481
- // lets assign the final filtered rows to all of the other columns
482
- const nonFilteredColumns = instance
483
- .getAllLeafColumns()
484
- .filter(
485
- column =>
486
- !instance
487
- .getState()
488
- .columnFilters?.find(d => d.id === column.id)
489
- )
490
-
491
- // This essentially enables faceted filter options to be built easily
492
- // using every column's preFilteredRows value
493
-
494
- nonFilteredColumns.forEach(column => {
495
- column.getPreFilteredRows = () => columnFilteredRowModel.rows
496
- })
497
-
498
- return columnFilteredRowModel
499
- },
500
- {
501
- key: 'getColumnFilteredRowModel',
502
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
474
+ getColumnFilteredRowModel: () => {
475
+ if (
476
+ !instance._getColumnFilteredRowModel &&
477
+ instance.options.getColumnFilteredRowModel
478
+ ) {
479
+ instance._getColumnFilteredRowModel =
480
+ instance.options.getColumnFilteredRowModel(instance)
503
481
  }
504
- ),
505
- getPreGlobalFilteredRowModel: () => instance.getColumnFilteredRowModel(),
506
- getGlobalFilteredRowModel: memo(
507
- () => [
508
- instance.getState().globalFilter,
509
- instance.getColumnFilteredRowModel(),
510
- instance.options.globalFilterRowsFn,
511
- ],
512
- (globalFilterValue, columnFilteredRowModel, globalFiltersFn) => {
513
- const globalFilteredRowModel = (() => {
514
- if (!globalFiltersFn || !globalFilterValue) {
515
- return columnFilteredRowModel
516
- }
517
482
 
518
- return globalFiltersFn(
519
- instance as TableInstance<TGenerics>,
520
- columnFilteredRowModel
521
- )
522
- })()
523
-
524
- // Now that each filtered column has it's partially filtered rows,
525
- // lets assign the final filtered rows to all of the other columns
526
- const nonFilteredColumns = instance
527
- .getAllLeafColumns()
528
- .filter(
529
- column =>
530
- !instance
531
- .getState()
532
- .columnFilters?.find(d => d.id === column.id)
533
- )
534
-
535
- // This essentially enables faceted filter options to be built easily
536
- // using every column's preFilteredRows value
483
+ if (!instance._getColumnFilteredRowModel) {
484
+ return instance.getPreColumnFilteredRowModel()
485
+ }
537
486
 
538
- nonFilteredColumns.forEach(column => {
539
- column.getPreFilteredRows = () => globalFilteredRowModel.rows
540
- })
487
+ return instance._getColumnFilteredRowModel()
488
+ },
489
+ getPreGlobalFilteredRowModel: () => instance.getColumnFilteredRowModel(),
490
+ getGlobalFilteredRowModel: () => {
491
+ if (
492
+ !instance._getGlobalFilteredRowModel &&
493
+ instance.options.getGlobalFilteredRowModel
494
+ ) {
495
+ instance._getGlobalFilteredRowModel =
496
+ instance.options.getGlobalFilteredRowModel(instance)
497
+ }
541
498
 
542
- return globalFilteredRowModel
543
- },
544
- {
545
- key: 'getGlobalFilteredRowModel',
546
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
547
- onChange: () => {
548
- instance._notifySortingReset()
549
- },
499
+ if (!instance._getGlobalFilteredRowModel) {
500
+ return instance.getPreGlobalFilteredRowModel()
550
501
  }
551
- ),
502
+
503
+ return instance._getGlobalFilteredRowModel()
504
+ },
552
505
  }
553
506
  },
554
507
  }
@@ -99,10 +99,9 @@ export type GroupingOptions<TGenerics extends AnyGenerics> = {
99
99
  autoResetGrouping?: boolean
100
100
  enableGrouping?: boolean
101
101
  enableGroupingRemoval?: boolean
102
- groupRowsFn?: (
103
- instance: TableInstance<TGenerics>,
104
- rowModel: RowModel<TGenerics>
105
- ) => RowModel<TGenerics>
102
+ getGroupedRowModel?: (
103
+ instance: TableInstance<TGenerics>
104
+ ) => () => RowModel<TGenerics>
106
105
 
107
106
  groupedColumnMode?: false | 'reorder' | 'remove'
108
107
  }
@@ -135,6 +134,7 @@ export type GroupingInstance<TGenerics extends AnyGenerics> = {
135
134
  getRowIsGrouped: (rowId: string) => boolean
136
135
  getPreGroupedRowModel: () => RowModel<TGenerics>
137
136
  getGroupedRowModel: () => RowModel<TGenerics>
137
+ _getGroupedRowModel?: () => RowModel<TGenerics>
138
138
  }
139
139
 
140
140
  //
@@ -186,6 +186,8 @@ export const Grouping = {
186
186
 
187
187
  return {
188
188
  _notifyGroupingReset: () => {
189
+ instance._notifyExpandedReset()
190
+
189
191
  if (!registered) {
190
192
  registered = true
191
193
  return
@@ -300,25 +302,21 @@ export const Grouping = {
300
302
  getRowIsGrouped: rowId => !!instance.getRow(rowId)?.groupingColumnId,
301
303
 
302
304
  getPreGroupedRowModel: () => instance.getSortedRowModel(),
303
- getGroupedRowModel: memo(
304
- () => [
305
- instance.getState().grouping,
306
- instance.getSortedRowModel(),
307
- instance.options.groupRowsFn,
308
- ],
309
- (grouping, rowModel, groupRowsFn) => {
310
- if (!groupRowsFn || !grouping.length) {
311
- return rowModel
312
- }
305
+ getGroupedRowModel: () => {
306
+ if (
307
+ !instance._getGroupedRowModel &&
308
+ instance.options.getGroupedRowModel
309
+ ) {
310
+ instance._getGroupedRowModel =
311
+ instance.options.getGroupedRowModel(instance)
312
+ }
313
313
 
314
- return groupRowsFn(instance, rowModel)
315
- },
316
- {
317
- key: 'getGroupedRowModel',
318
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
319
- onChange: () => instance._notifyExpandedReset(),
314
+ if (!instance._getGroupedRowModel) {
315
+ return instance.getPreGroupedRowModel()
320
316
  }
321
- ),
317
+
318
+ return instance._getGroupedRowModel()
319
+ },
322
320
  }
323
321
  },
324
322