@tanstack/table-core 8.0.0-alpha.13 → 8.0.0-alpha.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 (70) hide show
  1. package/build/cjs/core.js +17 -6
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/createTable.js +17 -9
  4. package/build/cjs/createTable.js.map +1 -1
  5. package/build/cjs/features/ColumnSizing.js +2 -2
  6. package/build/cjs/features/ColumnSizing.js.map +1 -1
  7. package/build/cjs/features/Expanding.js +2 -2
  8. package/build/cjs/features/Expanding.js.map +1 -1
  9. package/build/cjs/features/Filters.js +1 -1
  10. package/build/cjs/features/Filters.js.map +1 -1
  11. package/build/cjs/features/Grouping.js +13 -2
  12. package/build/cjs/features/Grouping.js.map +1 -1
  13. package/build/cjs/features/Headers.js +4 -4
  14. package/build/cjs/features/Headers.js.map +1 -1
  15. package/build/cjs/features/RowSelection.js.map +1 -1
  16. package/build/cjs/features/Visibility.js.map +1 -1
  17. package/build/cjs/index.js +1 -3
  18. package/build/cjs/index.js.map +1 -1
  19. package/build/cjs/types.js +0 -3
  20. package/build/cjs/types.js.map +1 -1
  21. package/build/cjs/utils/columnFilterRowsFn.js +1 -1
  22. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
  23. package/build/cjs/utils/expandRowsFn.js.map +1 -1
  24. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
  25. package/build/cjs/utils/groupRowsFn.js +1 -1
  26. package/build/cjs/utils/groupRowsFn.js.map +1 -1
  27. package/build/cjs/utils/paginateRowsFn.js.map +1 -1
  28. package/build/cjs/utils/sortRowsFn.js.map +1 -1
  29. package/build/cjs/utils.js +0 -24
  30. package/build/cjs/utils.js.map +1 -1
  31. package/build/esm/index.js +58 -50
  32. package/build/esm/index.js.map +1 -1
  33. package/build/stats-html.html +1 -1
  34. package/build/stats-react.json +268 -282
  35. package/build/types/core.d.ts +11 -9
  36. package/build/types/createTable.d.ts +24 -14
  37. package/build/types/features/ColumnSizing.d.ts +2 -3
  38. package/build/types/features/Grouping.d.ts +11 -5
  39. package/build/types/features/RowSelection.d.ts +2 -3
  40. package/build/types/features/Visibility.d.ts +1 -0
  41. package/build/types/types.d.ts +14 -7
  42. package/build/types/utils/columnFilterRowsFn.d.ts +2 -2
  43. package/build/types/utils/expandRowsFn.d.ts +2 -2
  44. package/build/types/utils/globalFilterRowsFn.d.ts +2 -2
  45. package/build/types/utils/groupRowsFn.d.ts +2 -2
  46. package/build/types/utils/paginateRowsFn.d.ts +2 -2
  47. package/build/types/utils/sortRowsFn.d.ts +2 -2
  48. package/build/types/utils.d.ts +4 -5
  49. package/build/umd/index.development.js +62 -58
  50. package/build/umd/index.development.js.map +1 -1
  51. package/build/umd/index.production.js +1 -1
  52. package/build/umd/index.production.js.map +1 -1
  53. package/package.json +1 -1
  54. package/src/core.tsx +63 -35
  55. package/src/createTable.tsx +49 -31
  56. package/src/features/ColumnSizing.ts +8 -14
  57. package/src/features/Expanding.ts +2 -2
  58. package/src/features/Filters.ts +1 -1
  59. package/src/features/Grouping.ts +30 -7
  60. package/src/features/Headers.ts +15 -3
  61. package/src/features/RowSelection.ts +2 -2
  62. package/src/features/Visibility.ts +1 -0
  63. package/src/types.ts +28 -15
  64. package/src/utils/columnFilterRowsFn.ts +3 -5
  65. package/src/utils/expandRowsFn.ts +2 -2
  66. package/src/utils/globalFilterRowsFn.ts +2 -2
  67. package/src/utils/groupRowsFn.ts +4 -4
  68. package/src/utils/paginateRowsFn.ts +2 -2
  69. package/src/utils/sortRowsFn.ts +2 -2
  70. package/src/utils.tsx +6 -45
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.13",
4
+ "version": "8.0.0-alpha.14",
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",
package/src/core.tsx CHANGED
@@ -3,7 +3,6 @@ import {
3
3
  functionalUpdate,
4
4
  propGetter,
5
5
  memo,
6
- flexRender,
7
6
  RequiredKeys,
8
7
  } from './utils'
9
8
 
@@ -27,9 +26,11 @@ import {
27
26
  CellProps,
28
27
  TableInstance,
29
28
  RowValues,
30
- Renderable,
31
29
  Please_use_the_create_table_column_utilities_to_define_columns,
32
30
  PartialGenerics,
31
+ CoreCell,
32
+ Renderable,
33
+ UseRenderer,
33
34
  } from './types'
34
35
 
35
36
  import { Visibility } from './features/Visibility'
@@ -38,7 +39,7 @@ import { Pinning } from './features/Pinning'
38
39
  import { Headers } from './features/Headers'
39
40
  import { Filters } from './features/Filters'
40
41
  import { Sorting } from './features/Sorting'
41
- import { Grouping, GroupingCell } from './features/Grouping'
42
+ import { Grouping } from './features/Grouping'
42
43
  import { Expanding } from './features/Expanding'
43
44
  import { ColumnSizing, defaultColumnSizing } from './features/ColumnSizing'
44
45
  import { Pagination } from './features/Pagination'
@@ -64,6 +65,7 @@ export type CoreOptions<TGenerics extends PartialGenerics> = {
64
65
  columns: ColumnDef<TGenerics>[]
65
66
  state: Partial<TableState>
66
67
  onStateChange: (updater: Updater<TableState>) => void
68
+ render: TGenerics['Render']
67
69
  debugAll?: boolean
68
70
  debugTable?: boolean
69
71
  debugHeaders?: boolean
@@ -140,6 +142,10 @@ export type TableCore<TGenerics extends PartialGenerics> = {
140
142
  getLeftTableWidth: () => number
141
143
  getCenterTableWidth: () => number
142
144
  getRightTableWidth: () => number
145
+ render: <TProps>(
146
+ template: Renderable<TGenerics, TProps>,
147
+ props: TProps
148
+ ) => string | null | ReturnType<UseRenderer<TGenerics>>
143
149
  }
144
150
 
145
151
  export type CoreRow<TGenerics extends PartialGenerics> = {
@@ -160,30 +166,37 @@ export type CoreColumnDef<TGenerics extends PartialGenerics> = {
160
166
  id: string
161
167
  accessorKey?: string & keyof TGenerics['Row']
162
168
  accessorFn?: AccessorFn<TGenerics['Row']>
163
- header?:
164
- | string
165
- | Renderable<{
166
- instance: TableInstance<TGenerics>
167
- header: Header<TGenerics>
168
- column: Column<TGenerics>
169
- }>
170
169
  width?: number
171
170
  minWidth?: number
172
171
  maxWidth?: number
173
172
  columns?: ColumnDef<TGenerics>[]
174
- footer?: Renderable<{
175
- instance: TableInstance<TGenerics>
176
- header: Header<TGenerics>
177
- column: Column<TGenerics>
178
- }>
179
- cell?: Renderable<{
180
- instance: TableInstance<TGenerics>
181
- row: Row<TGenerics>
182
- column: Column<TGenerics>
183
- cell: Cell<TGenerics>
184
- value: TGenerics['Value']
185
- }>
186
- defaultIsVisible?: boolean
173
+ header?: Renderable<
174
+ TGenerics,
175
+ {
176
+ instance: TableInstance<TGenerics>
177
+ header: Header<TGenerics>
178
+ column: Column<TGenerics>
179
+ }
180
+ >
181
+ footer?: Renderable<
182
+ TGenerics,
183
+ {
184
+ instance: TableInstance<TGenerics>
185
+ header: Header<TGenerics>
186
+ column: Column<TGenerics>
187
+ }
188
+ >
189
+ cell?: Renderable<
190
+ TGenerics,
191
+ {
192
+ instance: TableInstance<TGenerics>
193
+ row: Row<TGenerics>
194
+ column: Column<TGenerics>
195
+ cell: Cell<TGenerics>
196
+ value: TGenerics['Value']
197
+ }
198
+ >
199
+ meta?: TGenerics['ColumnMeta']
187
200
  [Please_use_the_create_table_column_utilities_to_define_columns]: true
188
201
  }
189
202
 
@@ -203,13 +216,11 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
203
216
  options: Options<TGenerics>
204
217
  ): TableInstance<TGenerics> {
205
218
  if (options.debugAll || options.debugTable) {
206
- console.info('Creating React Table Instance...')
219
+ console.info('Creating Table Instance...')
207
220
  }
208
221
 
209
222
  let instance = {} as TableInstance<TGenerics>
210
223
 
211
- let listeners: (() => void)[] = []
212
-
213
224
  const defaultOptions = features.reduce((obj, feature) => {
214
225
  return Object.assign(obj, (feature as any).getDefaultOptions?.(instance))
215
226
  }, {})
@@ -242,6 +253,17 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
242
253
  functionalUpdate(updater, instance.options)
243
254
  )
244
255
  },
256
+ render: (template, props) => {
257
+ if (typeof instance.options.render === 'function') {
258
+ return instance.options.render(template, props)
259
+ }
260
+
261
+ if (typeof template === 'function') {
262
+ return (template as Function)(props)
263
+ }
264
+
265
+ return template
266
+ },
245
267
 
246
268
  getRowId: (_: TGenerics['Row'], index: number, parent?: Row<TGenerics>) =>
247
269
  `${parent ? [parent.id, index].join('.') : index}`,
@@ -436,9 +458,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
436
458
 
437
459
  if (!column) {
438
460
  if (process.env.NODE_ENV !== 'production') {
439
- console.warn(
440
- `[React Table] Column with id ${columnId} does not exist.`
441
- )
461
+ console.warn(`[Table] Column with id ${columnId} does not exist.`)
442
462
  }
443
463
  throw new Error()
444
464
  }
@@ -465,7 +485,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
465
485
  },
466
486
 
467
487
  createCell: (row, column, value) => {
468
- const cell: Cell<TGenerics> = {
488
+ const cell: CoreCell<TGenerics> = {
469
489
  id: `${row.id}_${column.id}`,
470
490
  rowId: row.id,
471
491
  columnId: column.id,
@@ -475,14 +495,22 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
475
495
  getCellProps: userProps =>
476
496
  instance.getCellProps(row.id, column.id, userProps)!,
477
497
  renderCell: () =>
478
- flexRender(column.cell, { instance, column, row, cell, value }),
498
+ column.cell
499
+ ? instance.render(column.cell, {
500
+ instance,
501
+ column,
502
+ row,
503
+ cell: cell as Cell<TGenerics>,
504
+ value,
505
+ })
506
+ : null,
479
507
  }
480
508
 
481
509
  features.forEach(feature => {
482
510
  Object.assign(
483
511
  cell,
484
512
  (feature as any).createCell?.(
485
- cell as Cell<TGenerics> & GroupingCell,
513
+ cell as Cell<TGenerics>,
486
514
  column,
487
515
  row as Row<TGenerics>,
488
516
  instance
@@ -490,7 +518,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
490
518
  )
491
519
  }, {})
492
520
 
493
- return cell
521
+ return cell as Cell<TGenerics>
494
522
  },
495
523
 
496
524
  createRow: (id, original, rowIndex, depth, values) => {
@@ -671,7 +699,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
671
699
 
672
700
  if (!row) {
673
701
  if (process.env.NODE_ENV !== 'production') {
674
- throw new Error(`[React Table] could not find row with id ${rowId}`)
702
+ throw new Error(`[Table] could not find row with id ${rowId}`)
675
703
  }
676
704
  throw new Error()
677
705
  }
@@ -681,7 +709,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
681
709
  if (!cell) {
682
710
  if (process.env.NODE_ENV !== 'production') {
683
711
  throw new Error(
684
- `[React Table] could not find cell ${columnId} in row ${rowId}`
712
+ `[Table] could not find cell ${columnId} in row ${rowId}`
685
713
  )
686
714
  }
687
715
  throw new Error()
@@ -4,47 +4,38 @@ import { CustomSortingTypes } from './features/Sorting'
4
4
  import {
5
5
  ColumnDef,
6
6
  AccessorFn,
7
- DefaultGenerics,
8
7
  PartialGenerics,
9
8
  _NonGenerated,
9
+ AnyRender,
10
10
  } from './types'
11
11
  import { Overwrite, PartialKeys } from './utils'
12
12
 
13
- export type CreatTableFactory<TGenerics extends Partial<DefaultGenerics>> = <
14
- TRow
15
- >() => TableFactory<Overwrite<TGenerics, { Row: TRow }>>
13
+ export type CreateTableFactory<TGenerics extends PartialGenerics> = <
14
+ TSubGenerics extends {
15
+ Row: any
16
+ ColumnMeta?: object
17
+ }
18
+ >() => Table<
19
+ Overwrite<
20
+ TGenerics,
21
+ { Row: TSubGenerics['Row']; ColumnMeta: TSubGenerics['ColumnMeta'] }
22
+ >
23
+ >
16
24
 
17
25
  export type CreateTableFactoryOptions<
26
+ TRender extends AnyRender,
18
27
  TFilterFns extends CustomFilterTypes<any>,
19
28
  TSortingFns extends CustomSortingTypes<any>,
20
29
  TAggregationFns extends CustomAggregationTypes<any>
21
30
  > = {
31
+ render: TRender
22
32
  filterFns?: TFilterFns
23
33
  sortingFns?: TSortingFns
24
34
  aggregationFns?: TAggregationFns
25
35
  }
26
36
 
27
- export function createTableFactory<
28
- TFilterFns extends CustomFilterTypes<any>,
29
- TSortingFns extends CustomSortingTypes<any>,
30
- TAggregationFns extends CustomAggregationTypes<any>
31
- >(
32
- opts: CreateTableFactoryOptions<TFilterFns, TSortingFns, TAggregationFns>
33
- ): CreatTableFactory<
34
- Overwrite<
35
- PartialGenerics,
36
- {
37
- FilterFns: TFilterFns
38
- SortingFns: TSortingFns
39
- AggregationFns: TAggregationFns
40
- }
41
- >
42
- > {
43
- return () => _createTable(undefined, undefined, opts)
44
- }
45
-
46
- export type TableFactory<TGenerics extends Partial<DefaultGenerics>> = {
47
- __options: CreateTableFactoryOptions<any, any, any>
37
+ export type Table<TGenerics extends PartialGenerics> = {
38
+ __options: CreateTableFactoryOptions<any, any, any, any>
48
39
  createColumns: (columns: ColumnDef<TGenerics>[]) => ColumnDef<TGenerics>[]
49
40
  createGroup: (
50
41
  column: Overwrite<
@@ -62,7 +53,13 @@ export type TableFactory<TGenerics extends Partial<DefaultGenerics>> = {
62
53
  header?: string | ColumnDef<TGenerics>['header']
63
54
  }
64
55
  >,
65
- { accessorFn?: never; accessorKey?: never }
56
+ {
57
+ accessorFn?: never
58
+ accessorKey?: never
59
+ // This is sketchy, but allows the column helper pattern we want.
60
+ // Someone smarter than me could probably do this better.
61
+ columns?: ColumnDef<any>[]
62
+ }
66
63
  >
67
64
  ) => ColumnDef<TGenerics>
68
65
  createDisplayColumn: (
@@ -113,17 +110,38 @@ export type TableFactory<TGenerics extends Partial<DefaultGenerics>> = {
113
110
  >
114
111
  }
115
112
 
116
- export function createTable<TRow>() {
117
- return _createTable<Overwrite<PartialGenerics, { Row: TRow }>>()
113
+ type InitTable<TRender extends AnyRender> = {
114
+ createTableFactory: <TGenerics extends PartialGenerics>(
115
+ options?: CreateTableFactoryOptions<TRender, any, any, any>
116
+ ) => CreateTableFactory<Overwrite<TGenerics, { Render: TRender }>>
117
+ createTable: CreateTableFactory<
118
+ Overwrite<PartialGenerics, { Render: TRender }>
119
+ >
120
+ }
121
+
122
+ //
123
+
124
+ export function init<TRender extends AnyRender>(opts: {
125
+ render: TRender
126
+ }): InitTable<TRender> {
127
+ return {
128
+ createTableFactory: options => () =>
129
+ _createTable(undefined, undefined, { ...options, ...opts }),
130
+ createTable: () => _createTable(undefined, undefined, opts),
131
+ }
118
132
  }
119
133
 
120
134
  function _createTable<TGenerics extends PartialGenerics>(
121
135
  _?: undefined,
122
136
  __?: undefined,
123
- __options?: CreateTableFactoryOptions<any, any, any>
124
- ): TableFactory<TGenerics> {
137
+ __options?: CreateTableFactoryOptions<any, any, any, any>
138
+ ): Table<TGenerics> {
125
139
  return {
126
- __options: __options || {},
140
+ __options: __options ?? {
141
+ render: () => {
142
+ throw new Error()
143
+ },
144
+ },
127
145
  createColumns: columns => columns,
128
146
  createDisplayColumn: column => column as any,
129
147
  createGroup: column => column as any,
@@ -1,7 +1,3 @@
1
- import {
2
- MouseEvent as ReactMouseEvent,
3
- TouchEvent as ReactTouchEvent,
4
- } from 'react'
5
1
  import {
6
2
  Column,
7
3
  Getter,
@@ -49,8 +45,8 @@ export type ColumnSizingDefaultOptions = {
49
45
 
50
46
  export type ColumnResizerProps = {
51
47
  title?: string
52
- onMouseDown?: (e: ReactMouseEvent) => void
53
- onTouchStart?: (e: ReactTouchEvent) => void
48
+ onMouseDown?: (e: MouseEvent) => void
49
+ onTouchStart?: (e: TouchEvent) => void
54
50
  draggable?: boolean
55
51
  role?: string
56
52
  }
@@ -207,7 +203,7 @@ export const ColumnSizing = {
207
203
 
208
204
  const canResize = column.getCanResize()
209
205
 
210
- const onResizeStart = (e: ReactMouseEvent | ReactTouchEvent) => {
206
+ const onResizeStart = (e: MouseEvent | TouchEvent) => {
211
207
  if (isTouchStartEvent(e)) {
212
208
  // lets not respond to multiple touches (e.g. 2 or 3 fingers)
213
209
  if (e.touches && e.touches.length > 1) {
@@ -360,12 +356,12 @@ export const ColumnSizing = {
360
356
  title: 'Toggle Grouping',
361
357
  draggable: false,
362
358
  role: 'separator',
363
- onMouseDown: (e: ReactMouseEvent) => {
364
- e.persist()
359
+ onMouseDown: (e: MouseEvent & { persist?: () => void }) => {
360
+ e.persist?.()
365
361
  onResizeStart(e)
366
362
  },
367
- onTouchStart: (e: ReactTouchEvent) => {
368
- e.persist()
363
+ onTouchStart: (e: TouchEvent & { persist?: () => void }) => {
364
+ e.persist?.()
369
365
  onResizeStart(e)
370
366
  },
371
367
  }
@@ -425,8 +421,6 @@ export function passiveEventSupported() {
425
421
  return passiveSupported
426
422
  }
427
423
 
428
- function isTouchStartEvent(
429
- e: ReactTouchEvent | ReactMouseEvent
430
- ): e is ReactTouchEvent {
424
+ function isTouchStartEvent(e: TouchEvent | MouseEvent): e is TouchEvent {
431
425
  return e.type === 'touchstart'
432
426
  }
@@ -165,7 +165,7 @@ export const Expanding = {
165
165
  if (!row) {
166
166
  if (process.env.NODE_ENV !== 'production') {
167
167
  console.warn(
168
- `[ReactTable] getIsRowExpanded: no row found with id ${rowId}`
168
+ `[Table] getIsRowExpanded: no row found with id ${rowId}`
169
169
  )
170
170
  }
171
171
  throw new Error()
@@ -184,7 +184,7 @@ export const Expanding = {
184
184
  if (!row) {
185
185
  if (process.env.NODE_ENV !== 'production') {
186
186
  console.warn(
187
- `[ReactTable] getRowCanExpand: no row found with id ${rowId}`
187
+ `[Table] getRowCanExpand: no row found with id ${rowId}`
188
188
  )
189
189
  }
190
190
  throw new Error()
@@ -409,7 +409,7 @@ export const Filters = {
409
409
  if (!column) {
410
410
  if (process.env.NODE_ENV !== 'production') {
411
411
  console.warn(
412
- `React-Table: Could not find a column with id: ${columnId}`
412
+ `Table: Could not find a column with id: ${columnId}`
413
413
  )
414
414
  }
415
415
  throw new Error()
@@ -1,4 +1,3 @@
1
- import React, { MouseEvent, TouchEvent } from 'react'
2
1
  import { RowModel } from '..'
3
2
  import { BuiltInAggregationType, aggregationTypes } from '../aggregationTypes'
4
3
  import {
@@ -11,6 +10,8 @@ import {
11
10
  Row,
12
11
  Updater,
13
12
  PartialGenerics,
13
+ Renderable,
14
+ UseRenderer,
14
15
  } from '../types'
15
16
  import {
16
17
  functionalUpdate,
@@ -46,7 +47,16 @@ export type GroupingTableState = {
46
47
  export type GroupingColumnDef<TGenerics extends PartialGenerics> = {
47
48
  aggregationType?: AggregationType<Overwrite<TGenerics, { Value: any }>>
48
49
  aggregateValue?: (columnValue: unknown) => any
49
- renderAggregatedCell?: () => React.ReactNode
50
+ aggregatedCell?: Renderable<
51
+ TGenerics,
52
+ {
53
+ instance: TableInstance<TGenerics>
54
+ row: Row<TGenerics>
55
+ column: Column<TGenerics>
56
+ cell: Cell<TGenerics>
57
+ value: TGenerics['Value']
58
+ }
59
+ >
50
60
  enableGrouping?: boolean
51
61
  defaultCanGroup?: boolean
52
62
  }
@@ -68,10 +78,11 @@ export type GroupingRow = {
68
78
  getIsGrouped: () => boolean
69
79
  }
70
80
 
71
- export type GroupingCell = {
81
+ export type GroupingCell<TGenerics extends PartialGenerics> = {
72
82
  getIsGrouped: () => boolean
73
83
  getIsPlaceholder: () => boolean
74
84
  getIsAggregated: () => boolean
85
+ renderAggregatedCell: () => string | null | ReturnType<UseRenderer<TGenerics>>
75
86
  }
76
87
 
77
88
  export type ColumnDefaultOptions = {
@@ -277,7 +288,6 @@ export const Grouping = {
277
288
  title: canGroup ? 'Toggle Grouping' : undefined,
278
289
  onClick: canGroup
279
290
  ? (e: MouseEvent | TouchEvent) => {
280
- e.persist()
281
291
  column.toggleGrouping?.()
282
292
  }
283
293
  : undefined,
@@ -321,11 +331,11 @@ export const Grouping = {
321
331
  },
322
332
 
323
333
  createCell: <TGenerics extends PartialGenerics>(
324
- cell: Cell<TGenerics> & GroupingCell,
334
+ cell: Cell<TGenerics>,
325
335
  column: Column<TGenerics>,
326
336
  row: Row<TGenerics>,
327
- _instance: TableInstance<TGenerics>
328
- ): GroupingCell => {
337
+ instance: TableInstance<TGenerics>
338
+ ): GroupingCell<TGenerics> => {
329
339
  return {
330
340
  getIsGrouped: () =>
331
341
  column.getIsGrouped() && column.id === row.groupingColumnId,
@@ -334,6 +344,19 @@ export const Grouping = {
334
344
  !cell.getIsGrouped() &&
335
345
  !cell.getIsPlaceholder() &&
336
346
  row.subRows?.length > 1,
347
+ renderAggregatedCell: () => {
348
+ const template = column.aggregatedCell ?? column.cell
349
+
350
+ return template
351
+ ? instance.render(template, {
352
+ instance,
353
+ column,
354
+ row,
355
+ cell,
356
+ value: cell.value,
357
+ })
358
+ : null
359
+ },
337
360
  }
338
361
  },
339
362
 
@@ -14,7 +14,7 @@ import {
14
14
  TableInstance,
15
15
  Row,
16
16
  } from '../types'
17
- import { propGetter, memo, flexRender } from '../utils'
17
+ import { propGetter, memo } from '../utils'
18
18
  import { ColumnSizing } from './ColumnSizing'
19
19
 
20
20
  export type HeadersRow<TGenerics extends PartialGenerics> = {
@@ -224,9 +224,21 @@ export const Headers = {
224
224
  getFooterProps: userProps =>
225
225
  instance.getFooterProps(header.id, userProps)!,
226
226
  renderHeader: () =>
227
- flexRender(column.header, { instance, header, column }),
227
+ column.header
228
+ ? instance.render(column.header, {
229
+ instance,
230
+ header: header as Header<TGenerics>,
231
+ column,
232
+ })
233
+ : null,
228
234
  renderFooter: () =>
229
- flexRender(column.footer, { instance, header, column }),
235
+ column.footer
236
+ ? instance.render(column.footer, {
237
+ instance,
238
+ header: header as Header<TGenerics>,
239
+ column,
240
+ })
241
+ : null,
230
242
  }
231
243
 
232
244
  // Yes, we have to convert instance to unknown, because we know more than the compiler here.
@@ -1,4 +1,3 @@
1
- import React, { MouseEvent, TouchEvent } from 'react'
2
1
  import {
3
2
  Getter,
4
3
  OnChangeFn,
@@ -8,6 +7,7 @@ import {
8
7
  Row,
9
8
  RowModel,
10
9
  Updater,
10
+ AnyGenerics,
11
11
  } from '../types'
12
12
  import { functionalUpdate, makeStateUpdater, memo, propGetter } from '../utils'
13
13
 
@@ -581,7 +581,7 @@ const mutateRowIsSelected = <TGenerics extends PartialGenerics>(
581
581
  }
582
582
  }
583
583
 
584
- export function selectRowsFn<TGenerics extends PartialGenerics>(
584
+ export function selectRowsFn<TGenerics extends AnyGenerics>(
585
585
  instance: TableInstance<TGenerics>,
586
586
  rowModel: RowModel<TGenerics>
587
587
  ): RowModel<TGenerics> {
@@ -48,6 +48,7 @@ type ToggleAllColumnsVisibilityProps = {}
48
48
  export type VisibilityColumnDef = {
49
49
  enableHiding?: boolean
50
50
  defaultCanHide?: boolean
51
+ defaultIsVisible?: boolean
51
52
  }
52
53
 
53
54
  export type VisibilityRow<TGenerics extends PartialGenerics> = {
package/src/types.ts CHANGED
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import {
3
2
  CoreColumn,
4
3
  CoreColumnDef,
@@ -42,6 +41,7 @@ import {
42
41
  SortingTableState,
43
42
  } from './features/Sorting'
44
43
  import {
44
+ GroupingCell,
45
45
  GroupingColumn,
46
46
  GroupingColumnDef,
47
47
  GroupingInstance,
@@ -55,7 +55,7 @@ import {
55
55
  ExpandedTableState,
56
56
  ExpandedRow,
57
57
  } from './features/Expanding'
58
- import { Overwrite } from './utils'
58
+ import { Overwrite, PartialKeys } from './utils'
59
59
  import {
60
60
  ColumnSizingColumn,
61
61
  ColumnSizingColumnDef,
@@ -76,20 +76,27 @@ import {
76
76
  RowSelectionTableState,
77
77
  } from './features/RowSelection'
78
78
 
79
- // declare global {
80
- // const process.env.NODE_ENV !== 'production': boolean
81
- // }
82
-
83
79
  export type DefaultGenerics = {
84
80
  Row: unknown
85
81
  Value: unknown
86
82
  FilterFns: object
87
83
  SortingFns: object
88
84
  AggregationFns: object
85
+ Render: unknown
86
+ ColumnMeta: object
89
87
  }
90
88
 
89
+ export type AnyRender = (Comp: any, props: any) => any
90
+
91
+ export type UseRenderer<TGenerics extends PartialGenerics> =
92
+ TGenerics['Render'] extends (...args: any) => any ? TGenerics['Render'] : any
93
+
91
94
  export type PartialGenerics = Partial<DefaultGenerics>
92
95
 
96
+ export type AnyGenerics = {
97
+ [TKey in keyof PartialGenerics]: any
98
+ }
99
+
93
100
  export type TableInstance<TGenerics extends PartialGenerics> =
94
101
  TableCore<TGenerics> &
95
102
  VisibilityInstance<TGenerics> &
@@ -104,11 +111,6 @@ export type TableInstance<TGenerics extends PartialGenerics> =
104
111
  PaginationInstance<TGenerics> &
105
112
  RowSelectionInstance<TGenerics>
106
113
 
107
- export type Renderable<TProps> =
108
- | React.ReactNode
109
- | React.FunctionComponent<TProps>
110
- | React.Component<TProps>
111
-
112
114
  //
113
115
 
114
116
  export type Options<TGenerics extends PartialGenerics> =
@@ -167,6 +169,10 @@ export type _NonGenerated<T> = Overwrite<
167
169
  }
168
170
  >
169
171
 
172
+ export type Renderable<TGenerics extends PartialGenerics, TProps> =
173
+ | string
174
+ | ((props: TProps) => ReturnType<UseRenderer<TGenerics>>)
175
+
170
176
  export type ColumnDef<TGenerics extends PartialGenerics> =
171
177
  CoreColumnDef<TGenerics> &
172
178
  VisibilityColumnDef &
@@ -185,7 +191,10 @@ export type Column<TGenerics extends PartialGenerics> = ColumnDef<TGenerics> &
185
191
  GroupingColumn<TGenerics> &
186
192
  ColumnSizingColumn<TGenerics>
187
193
 
188
- export type Cell<TGenerics extends PartialGenerics> = {
194
+ export type Cell<TGenerics extends PartialGenerics> = CoreCell<TGenerics> &
195
+ GroupingCell<TGenerics>
196
+
197
+ export type CoreCell<TGenerics extends PartialGenerics> = {
189
198
  id: string
190
199
  rowId: string
191
200
  columnId: string
@@ -193,7 +202,7 @@ export type Cell<TGenerics extends PartialGenerics> = {
193
202
  row: Row<TGenerics>
194
203
  column: Column<TGenerics>
195
204
  getCellProps: PropGetter<CellProps>
196
- renderCell: () => React.ReactNode
205
+ renderCell: () => string | null | ReturnType<UseRenderer<TGenerics>>
197
206
  }
198
207
 
199
208
  export type Header<TGenerics extends PartialGenerics> = CoreHeader<TGenerics> &
@@ -212,8 +221,12 @@ export type CoreHeader<TGenerics extends PartialGenerics> = {
212
221
  getLeafHeaders: () => Header<TGenerics>[]
213
222
  isPlaceholder?: boolean
214
223
  placeholderId?: string
215
- renderHeader: (options?: { renderPlaceholder?: boolean }) => React.ReactNode
216
- renderFooter: (options?: { renderPlaceholder?: boolean }) => React.ReactNode
224
+ renderHeader: (options?: {
225
+ renderPlaceholder?: boolean
226
+ }) => string | null | ReturnType<UseRenderer<TGenerics>>
227
+ renderFooter: (options?: {
228
+ renderPlaceholder?: boolean
229
+ }) => string | null | ReturnType<UseRenderer<TGenerics>>
217
230
  }
218
231
 
219
232
  export type HeaderGroup<TGenerics extends PartialGenerics> = {