@tanstack/table-core 8.0.0-alpha.28 → 8.0.0-alpha.34

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 (124) 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 +50 -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 +9 -3
  19. package/build/cjs/features/RowSelection.js.map +1 -1
  20. package/build/cjs/features/Sorting.js +11 -17
  21. package/build/cjs/features/Sorting.js.map +1 -1
  22. package/build/cjs/features/Visibility.js.map +1 -1
  23. package/build/cjs/filterTypes.js.map +1 -1
  24. package/build/cjs/index.js +19 -12
  25. package/build/cjs/index.js.map +1 -1
  26. package/build/cjs/sortTypes.js.map +1 -1
  27. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  28. package/build/cjs/utils/getColumnFilteredRowModelSync.js +115 -0
  29. package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -0
  30. package/build/cjs/utils/getCoreRowModelAsync.js +127 -0
  31. package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -0
  32. package/build/cjs/utils/getCoreRowModelSync.js +104 -0
  33. package/build/cjs/utils/getCoreRowModelSync.js.map +1 -0
  34. package/build/cjs/utils/getExpandedRowModel.js +61 -0
  35. package/build/cjs/utils/getExpandedRowModel.js.map +1 -0
  36. package/build/cjs/utils/getGlobalFilteredRowModelSync.js +91 -0
  37. package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +1 -0
  38. package/build/cjs/utils/getGroupedRowModel.js +176 -0
  39. package/build/cjs/utils/getGroupedRowModel.js.map +1 -0
  40. package/build/cjs/utils/getPaginationRowModel.js +61 -0
  41. package/build/cjs/utils/getPaginationRowModel.js.map +1 -0
  42. package/build/cjs/utils/getSortedRowModelSync.js +118 -0
  43. package/build/cjs/utils/getSortedRowModelSync.js.map +1 -0
  44. package/build/cjs/utils.js +159 -20
  45. package/build/cjs/utils.js.map +1 -1
  46. package/build/esm/index.js +893 -500
  47. package/build/esm/index.js.map +1 -1
  48. package/build/stats-html.html +1 -1
  49. package/build/stats-react.json +408 -300
  50. package/build/types/aggregationTypes.d.ts +1 -1
  51. package/build/types/core.d.ts +11 -1
  52. package/build/types/createTable.d.ts +2 -4
  53. package/build/types/features/Expanding.d.ts +2 -1
  54. package/build/types/features/Filters.d.ts +6 -2
  55. package/build/types/features/Grouping.d.ts +3 -2
  56. package/build/types/features/Pagination.d.ts +2 -1
  57. package/build/types/features/Sorting.d.ts +2 -1
  58. package/build/types/index.d.ts +8 -6
  59. package/build/types/types.d.ts +3 -2
  60. package/build/types/utils/getColumnFilteredRowModelAsync.d.ts +4 -0
  61. package/build/types/utils/getColumnFilteredRowModelSync.d.ts +2 -0
  62. package/build/types/utils/getCoreRowModelAsync.d.ts +4 -0
  63. package/build/types/utils/getCoreRowModelSync.d.ts +2 -0
  64. package/build/types/utils/getExpandedRowModel.d.ts +7 -0
  65. package/build/types/utils/getGlobalFilteredRowModelAsync.d.ts +4 -0
  66. package/build/types/utils/getGlobalFilteredRowModelSync.d.ts +2 -0
  67. package/build/types/utils/getGroupedRowModel.d.ts +2 -0
  68. package/build/types/utils/getPaginationRowModel.d.ts +4 -0
  69. package/build/types/utils/{sortRowsQuicksortFn.d.ts → getSortedRowModelAsync.d.ts} +3 -1
  70. package/build/types/utils/getSortedRowModelSync.d.ts +2 -0
  71. package/build/types/utils.d.ts +16 -0
  72. package/build/umd/index.development.js +903 -505
  73. package/build/umd/index.development.js.map +1 -1
  74. package/build/umd/index.production.js +1 -1
  75. package/build/umd/index.production.js.map +1 -1
  76. package/package.json +3 -1
  77. package/src/aggregationTypes.ts +1 -1
  78. package/src/core.tsx +66 -99
  79. package/src/createTable.tsx +2 -6
  80. package/src/features/Expanding.ts +21 -29
  81. package/src/features/Filters.ts +53 -100
  82. package/src/features/Grouping.ts +19 -21
  83. package/src/features/Pagination.ts +19 -28
  84. package/src/features/RowSelection.ts +5 -3
  85. package/src/features/Sorting.ts +20 -24
  86. package/src/index.tsx +8 -6
  87. package/src/types.ts +4 -1
  88. package/src/utils/getColumnFilteredRowModelAsync.ts +119 -0
  89. package/src/utils/getColumnFilteredRowModelSync.ts +99 -0
  90. package/src/utils/getCoreRowModelAsync.ts +105 -0
  91. package/src/utils/getCoreRowModelSync.ts +107 -0
  92. package/src/utils/getExpandedRowModel.ts +58 -0
  93. package/src/utils/getGlobalFilteredRowModelAsync.ts +97 -0
  94. package/src/utils/getGlobalFilteredRowModelSync.ts +76 -0
  95. package/src/utils/getGroupedRowModel.ts +191 -0
  96. package/src/utils/getPaginationRowModel.ts +45 -0
  97. package/src/utils/getSortedRowModelAsync.ts +201 -0
  98. package/src/utils/getSortedRowModelSync.ts +118 -0
  99. package/src/utils.tsx +193 -21
  100. package/build/cjs/utils/columnFilterRowsFn.js +0 -73
  101. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  102. package/build/cjs/utils/expandRowsFn.js +0 -37
  103. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  104. package/build/cjs/utils/globalFilterRowsFn.js +0 -49
  105. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  106. package/build/cjs/utils/groupRowsFn.js +0 -155
  107. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  108. package/build/cjs/utils/paginateRowsFn.js +0 -44
  109. package/build/cjs/utils/paginateRowsFn.js.map +0 -1
  110. package/build/cjs/utils/sortRowsFn.js +0 -94
  111. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  112. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  113. package/build/types/utils/expandRowsFn.d.ts +0 -2
  114. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  115. package/build/types/utils/groupRowsFn.d.ts +0 -2
  116. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  117. package/build/types/utils/sortRowsFn.d.ts +0 -2
  118. package/src/utils/columnFilterRowsFn.ts +0 -56
  119. package/src/utils/expandRowsFn.ts +0 -34
  120. package/src/utils/globalFilterRowsFn.ts +0 -39
  121. package/src/utils/groupRowsFn.ts +0 -174
  122. package/src/utils/paginateRowsFn.ts +0 -28
  123. package/src/utils/sortRowsFn.ts +0 -99
  124. 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.28",
4
+ "version": "8.0.0-alpha.34",
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",
@@ -14,6 +14,8 @@
14
14
  },
15
15
  "keywords": [
16
16
  "react",
17
+ "vue",
18
+ "solid",
17
19
  "table",
18
20
  "table-core",
19
21
  "datagrid"
@@ -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,8 @@ 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'
50
+ import React from 'react'
49
51
 
50
52
  const features: TableFeature[] = [
51
53
  Headers,
@@ -61,12 +63,19 @@ const features: TableFeature[] = [
61
63
  ColumnSizing,
62
64
  ]
63
65
 
66
+ export type CoreTableState = {
67
+ coreProgress: number
68
+ }
69
+
64
70
  export type CoreOptions<TGenerics extends AnyGenerics> = {
65
71
  data: TGenerics['Row'][]
66
72
  columns: ColumnDef<TGenerics>[]
67
73
  state: Partial<TableState>
68
74
  onStateChange: (updater: Updater<TableState>) => void
69
75
  render: TGenerics['Render']
76
+ getCoreRowModel: (
77
+ instance: TableInstance<TGenerics>
78
+ ) => () => RowModel<TGenerics>
70
79
  debugAll?: boolean
71
80
  debugTable?: boolean
72
81
  debugHeaders?: boolean
@@ -84,6 +93,11 @@ export type CoreOptions<TGenerics extends AnyGenerics> = {
84
93
  parent?: Row<TGenerics>
85
94
  ) => string
86
95
  autoResetAll?: boolean
96
+ mergeOptions?: (
97
+ defaultOptions: TableFeature,
98
+ options: Partial<Options<TGenerics>>
99
+ ) => Options<TGenerics>
100
+ meta?: TGenerics['TableMeta']
87
101
  }
88
102
 
89
103
  export type TableCore<TGenerics extends AnyGenerics> = {
@@ -91,6 +105,8 @@ export type TableCore<TGenerics extends AnyGenerics> = {
91
105
  reset: () => void
92
106
  options: RequiredKeys<Options<TGenerics>, 'state'>
93
107
  setOptions: (newOptions: Updater<Options<TGenerics>>) => void
108
+ queue: (cb: () => void) => void
109
+ willUpdate: () => void
94
110
  getRowId: (
95
111
  _: TGenerics['Row'],
96
112
  index: number,
@@ -124,6 +140,7 @@ export type TableCore<TGenerics extends AnyGenerics> = {
124
140
  values: Record<string, any>
125
141
  ) => Row<TGenerics>
126
142
  getCoreRowModel: () => RowModel<TGenerics>
143
+ _getCoreRowModel?: () => RowModel<TGenerics>
127
144
  getRowModel: () => RowModel<TGenerics>
128
145
  getRow: (id: string) => Row<TGenerics>
129
146
  getCell: (rowId: string, columnId: string) => Cell<TGenerics>
@@ -146,6 +163,7 @@ export type TableCore<TGenerics extends AnyGenerics> = {
146
163
  template: Renderable<TGenerics, TProps>,
147
164
  props: TProps
148
165
  ) => string | null | ReturnType<UseRenderer<TGenerics>>
166
+ getOverallProgress: () => number
149
167
  }
150
168
 
151
169
  export type CoreRow<TGenerics extends AnyGenerics> = {
@@ -232,26 +250,54 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
232
250
 
233
251
  instance.options = buildOptions(options)
234
252
 
253
+ const coreInitialState: CoreTableState = {
254
+ coreProgress: 1,
255
+ }
256
+
235
257
  const initialState = {
258
+ ...coreInitialState,
236
259
  ...features.reduce((obj, feature) => {
237
260
  return Object.assign(obj, feature.getInitialState?.())
238
261
  }, {}),
239
262
  ...(options.initialState ?? {}),
240
263
  } as TableState
241
264
 
265
+ const queued: (() => void)[] = []
266
+ let queuedTimeout: NodeJS.Timeout
267
+
242
268
  const finalInstance: TableInstance<TGenerics> = {
243
269
  ...instance,
244
270
  ...features.reduce((obj, feature) => {
245
271
  return Object.assign(obj, feature.getInstance?.(instance))
246
272
  }, {}),
273
+ queue: cb => {
274
+ queued.push(cb)
275
+ if (!queuedTimeout) {
276
+ queuedTimeout = setTimeout(() => {
277
+ instance.setState(old => ({ ...old }))
278
+ })
279
+ }
280
+ },
281
+ willUpdate: () => {
282
+ clearTimeout(queuedTimeout)
283
+ while (queued.length) {
284
+ queued.shift()!()
285
+ }
286
+ },
247
287
  initialState,
248
288
  reset: () => {
249
289
  instance.setState(instance.initialState)
250
290
  },
251
291
  setOptions: updater => {
252
- instance.options = buildOptions(
253
- functionalUpdate(updater, instance.options)
254
- )
292
+ const newOptions = functionalUpdate(updater, instance.options)
293
+ if (instance.options.mergeOptions) {
294
+ instance.options = instance.options.mergeOptions(
295
+ defaultOptions,
296
+ newOptions
297
+ )
298
+ } else {
299
+ instance.options = buildOptions(newOptions)
300
+ }
255
301
  },
256
302
  render: (template, props) => {
257
303
  if (typeof instance.options.render === 'function') {
@@ -557,103 +603,13 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
557
603
  return row as Row<TGenerics>
558
604
  },
559
605
 
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
- },
606
+ getCoreRowModel: () => {
607
+ if (!instance._getCoreRowModel) {
608
+ instance._getCoreRowModel = instance.options.getCoreRowModel(instance)
655
609
  }
656
- ),
610
+
611
+ return instance._getCoreRowModel()
612
+ },
657
613
 
658
614
  // The final calls start at the bottom of the model,
659
615
  // expanded rows, which then work their way up
@@ -764,6 +720,17 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
764
720
  instance.getRightHeaderGroups()[0]?.headers.reduce((sum, header) => {
765
721
  return sum + header.getWidth()
766
722
  }, 0) ?? 0,
723
+
724
+ getOverallProgress: () => {
725
+ const { coreProgress, columnFiltersProgress, globalFilterProgress } =
726
+ instance.getState()
727
+
728
+ return mean(() =>
729
+ [coreProgress, columnFiltersProgress, globalFilterProgress].filter(
730
+ d => d < 1
731
+ )
732
+ ) as number
733
+ },
767
734
  }
768
735
 
769
736
  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