@tanstack/table-core 8.0.0-alpha.53 → 8.0.0-alpha.57
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.
- package/build/cjs/core.js +9 -384
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Cells.js +122 -0
- package/build/cjs/features/Cells.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +90 -37
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js +216 -0
- package/build/cjs/features/Columns.js.map +1 -0
- package/build/cjs/features/Expanding.js +1 -1
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +1 -1
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +1 -1
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +78 -153
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js +2 -2
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +1 -1
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +172 -2
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +1 -1
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +99 -0
- package/build/cjs/features/Rows.js.map +1 -0
- package/build/cjs/features/Sorting.js +1 -1
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +51 -17
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js.map +1 -1
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -1
- package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -1
- package/build/cjs/utils/getCoreRowModelSync.js.map +1 -1
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModelSync.js.map +1 -1
- package/build/cjs/utils.js +2 -2
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +879 -693
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +420 -318
- package/build/types/core.d.ts +5 -82
- package/build/types/createTable.d.ts +4 -4
- package/build/types/features/Cells.d.ts +14 -0
- package/build/types/features/ColumnSizing.d.ts +31 -23
- package/build/types/features/Columns.d.ts +54 -0
- package/build/types/features/Expanding.d.ts +6 -6
- package/build/types/features/Filters.d.ts +14 -14
- package/build/types/features/Grouping.d.ts +16 -16
- package/build/types/features/Headers.d.ts +5 -13
- package/build/types/features/Ordering.d.ts +5 -5
- package/build/types/features/Pagination.d.ts +5 -5
- package/build/types/features/Pinning.d.ts +21 -7
- package/build/types/features/RowSelection.d.ts +8 -8
- package/build/types/features/Rows.d.ts +29 -0
- package/build/types/features/Sorting.d.ts +12 -12
- package/build/types/features/Visibility.d.ts +11 -6
- package/build/types/filterFns.d.ts +10 -10
- package/build/types/sortingFns.d.ts +7 -7
- package/build/types/types.d.ts +37 -33
- package/build/types/utils/filterRowsUtils.d.ts +3 -3
- package/build/types/utils/getColumnFilteredRowModelAsync.d.ts +2 -2
- package/build/types/utils/getColumnFilteredRowModelSync.d.ts +2 -2
- package/build/types/utils/getCoreRowModelAsync.d.ts +2 -2
- package/build/types/utils/getCoreRowModelSync.d.ts +2 -2
- package/build/types/utils/getExpandedRowModel.d.ts +3 -3
- package/build/types/utils/getGlobalFilteredRowModelAsync.d.ts +2 -2
- package/build/types/utils/getGlobalFilteredRowModelSync.d.ts +2 -2
- package/build/types/utils/getGroupedRowModel.d.ts +2 -2
- package/build/types/utils/getPaginationRowModel.d.ts +2 -2
- package/build/types/utils/getSortedRowModelAsync.d.ts +4 -4
- package/build/types/utils/getSortedRowModelSync.d.ts +2 -2
- package/build/types/utils.d.ts +0 -1
- package/build/umd/index.development.js +857 -671
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/core.ts +32 -554
- package/src/createTable.ts +12 -5
- package/src/features/Cells.ts +156 -0
- package/src/features/ColumnSizing.ts +109 -58
- package/src/features/Columns.ts +290 -0
- package/src/features/Expanding.ts +6 -7
- package/src/features/Filters.ts +14 -15
- package/src/features/Grouping.ts +16 -17
- package/src/features/Headers.ts +51 -142
- package/src/features/Ordering.ts +8 -7
- package/src/features/Pagination.ts +5 -6
- package/src/features/Pinning.ts +198 -8
- package/src/features/RowSelection.ts +9 -10
- package/src/features/Rows.ts +151 -0
- package/src/features/Sorting.ts +12 -13
- package/src/features/Visibility.ts +73 -27
- package/src/filterFns.ts +10 -10
- package/src/sortingFns.ts +7 -7
- package/src/types.ts +47 -65
- package/src/utils/filterRowsUtils.ts +3 -3
- package/src/utils/getColumnFilteredRowModelAsync.ts +2 -2
- package/src/utils/getColumnFilteredRowModelSync.ts +2 -2
- package/src/utils/getCoreRowModelAsync.ts +2 -2
- package/src/utils/getCoreRowModelSync.ts +2 -2
- package/src/utils/getExpandedRowModel.ts +3 -3
- package/src/utils/getGlobalFilteredRowModelAsync.ts +2 -2
- package/src/utils/getGlobalFilteredRowModelSync.ts +2 -2
- package/src/utils/getGroupedRowModel.ts +3 -3
- package/src/utils/getPaginationRowModel.ts +2 -2
- package/src/utils/getSortedRowModelAsync.ts +4 -4
- package/src/utils/getSortedRowModelSync.ts +2 -2
- package/src/utils.ts +3 -5
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { features } from 'process'
|
|
2
|
+
import {
|
|
3
|
+
Cell,
|
|
4
|
+
Column,
|
|
5
|
+
Header,
|
|
6
|
+
TableGenerics,
|
|
7
|
+
TableInstance,
|
|
8
|
+
Row,
|
|
9
|
+
AccessorFn,
|
|
10
|
+
ColumnDef,
|
|
11
|
+
Renderable,
|
|
12
|
+
HeaderRenderProps,
|
|
13
|
+
} from '../types'
|
|
14
|
+
import { memo } from '../utils'
|
|
15
|
+
import { ColumnPinningPosition } from './Pinning'
|
|
16
|
+
|
|
17
|
+
export type CoreColumnDefType = 'data' | 'display' | 'group'
|
|
18
|
+
|
|
19
|
+
export type CoreColumnDef<TGenerics extends TableGenerics> = {
|
|
20
|
+
id: string
|
|
21
|
+
accessorKey?: string & keyof TGenerics['Row']
|
|
22
|
+
accessorFn?: AccessorFn<TGenerics['Row']>
|
|
23
|
+
columns?: ColumnDef<TGenerics>[]
|
|
24
|
+
header?: Renderable<
|
|
25
|
+
TGenerics,
|
|
26
|
+
{
|
|
27
|
+
instance: TableInstance<TGenerics>
|
|
28
|
+
header: Header<TGenerics>
|
|
29
|
+
column: Column<TGenerics>
|
|
30
|
+
}
|
|
31
|
+
>
|
|
32
|
+
footer?: Renderable<
|
|
33
|
+
TGenerics,
|
|
34
|
+
{
|
|
35
|
+
instance: TableInstance<TGenerics>
|
|
36
|
+
header: Header<TGenerics>
|
|
37
|
+
column: Column<TGenerics>
|
|
38
|
+
}
|
|
39
|
+
>
|
|
40
|
+
cell?: Renderable<
|
|
41
|
+
TGenerics,
|
|
42
|
+
{
|
|
43
|
+
instance: TableInstance<TGenerics>
|
|
44
|
+
row: Row<TGenerics>
|
|
45
|
+
column: Column<TGenerics>
|
|
46
|
+
cell: Cell<TGenerics>
|
|
47
|
+
value: TGenerics['Value']
|
|
48
|
+
}
|
|
49
|
+
>
|
|
50
|
+
meta?: TGenerics['ColumnMeta']
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type CoreColumn<TGenerics extends TableGenerics> = {
|
|
54
|
+
id: string
|
|
55
|
+
depth: number
|
|
56
|
+
accessorFn?: AccessorFn<TGenerics['Row']>
|
|
57
|
+
columnDef: ColumnDef<TGenerics>
|
|
58
|
+
columnDefType: CoreColumnDefType
|
|
59
|
+
columns: Column<TGenerics>[]
|
|
60
|
+
parent?: Column<TGenerics>
|
|
61
|
+
getFlatColumns: () => Column<TGenerics>[]
|
|
62
|
+
getLeafColumns: () => Column<TGenerics>[]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type ColumnsOptions<TGenerics extends TableGenerics> = {
|
|
66
|
+
columns: ColumnDef<TGenerics>[]
|
|
67
|
+
defaultColumn?: Partial<ColumnDef<TGenerics>>
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type ColumnsInstance<TGenerics extends TableGenerics> = {
|
|
71
|
+
getDefaultColumn: () => Partial<ColumnDef<TGenerics>>
|
|
72
|
+
getColumnDefs: () => ColumnDef<TGenerics>[]
|
|
73
|
+
createColumn: (
|
|
74
|
+
columnDef: ColumnDef<TGenerics>,
|
|
75
|
+
depth: number,
|
|
76
|
+
parent?: Column<TGenerics>
|
|
77
|
+
) => Column<TGenerics>
|
|
78
|
+
getAllColumns: () => Column<TGenerics>[]
|
|
79
|
+
getAllFlatColumns: () => Column<TGenerics>[]
|
|
80
|
+
getAllFlatColumnsById: () => Record<string, Column<TGenerics>>
|
|
81
|
+
getAllLeafColumns: () => Column<TGenerics>[]
|
|
82
|
+
getColumn: (columnId: string) => Column<TGenerics>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
//
|
|
86
|
+
|
|
87
|
+
export const Columns = {
|
|
88
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
89
|
+
instance: TableInstance<TGenerics>
|
|
90
|
+
): ColumnsInstance<TGenerics> => {
|
|
91
|
+
return {
|
|
92
|
+
getDefaultColumn: memo(
|
|
93
|
+
() => [instance.options.defaultColumn],
|
|
94
|
+
defaultColumn => {
|
|
95
|
+
defaultColumn = (defaultColumn ?? {}) as Partial<ColumnDef<TGenerics>>
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
header: (props: HeaderRenderProps<Header<TGenerics>>) =>
|
|
99
|
+
props.header.column.id,
|
|
100
|
+
footer: (props: HeaderRenderProps<Header<TGenerics>>) =>
|
|
101
|
+
props.header.column.id,
|
|
102
|
+
cell: ({ value = '' }: { value: any }): JSX.Element =>
|
|
103
|
+
typeof value === 'boolean' ? value.toString() : value,
|
|
104
|
+
...instance._features.reduce((obj, feature) => {
|
|
105
|
+
return Object.assign(obj, feature.getDefaultColumn?.())
|
|
106
|
+
}, {}),
|
|
107
|
+
...defaultColumn,
|
|
108
|
+
} as Partial<ColumnDef<TGenerics>>
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
debug: () =>
|
|
112
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
113
|
+
key: 'getDefaultColumn',
|
|
114
|
+
}
|
|
115
|
+
),
|
|
116
|
+
|
|
117
|
+
getColumnDefs: () => instance.options.columns,
|
|
118
|
+
|
|
119
|
+
createColumn: (
|
|
120
|
+
columnDef: ColumnDef<TGenerics> & { columnDefType?: CoreColumnDefType },
|
|
121
|
+
depth: number,
|
|
122
|
+
parent
|
|
123
|
+
) => {
|
|
124
|
+
const defaultColumn = instance.getDefaultColumn()
|
|
125
|
+
|
|
126
|
+
let id =
|
|
127
|
+
columnDef.id ??
|
|
128
|
+
columnDef.accessorKey ??
|
|
129
|
+
(typeof columnDef.header === 'string' ? columnDef.header : undefined)
|
|
130
|
+
|
|
131
|
+
let accessorFn: AccessorFn<TGenerics['Row']> | undefined
|
|
132
|
+
|
|
133
|
+
if (columnDef.accessorFn) {
|
|
134
|
+
accessorFn = columnDef.accessorFn
|
|
135
|
+
} else if (columnDef.accessorKey) {
|
|
136
|
+
accessorFn = (originalRow?: TGenerics['Row']) =>
|
|
137
|
+
(originalRow as any)[columnDef.accessorKey]
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!id) {
|
|
141
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
142
|
+
throw new Error(
|
|
143
|
+
columnDef.accessorFn
|
|
144
|
+
? `Columns require an id when using an accessorFn`
|
|
145
|
+
: `Columns require an id when using a non-string header`
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
throw new Error()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let column: CoreColumn<TGenerics> = {
|
|
152
|
+
...defaultColumn,
|
|
153
|
+
...columnDef,
|
|
154
|
+
id: `${id}`,
|
|
155
|
+
accessorFn,
|
|
156
|
+
parent: parent as any,
|
|
157
|
+
depth,
|
|
158
|
+
columnDef,
|
|
159
|
+
columnDefType: columnDef.columnDefType as CoreColumnDefType,
|
|
160
|
+
columns: [],
|
|
161
|
+
getFlatColumns: memo(
|
|
162
|
+
() => [true],
|
|
163
|
+
() => {
|
|
164
|
+
return [
|
|
165
|
+
column as Column<TGenerics>,
|
|
166
|
+
...column.columns?.flatMap(d => d.getFlatColumns()),
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
key: 'column.getFlatColumns',
|
|
171
|
+
debug: () =>
|
|
172
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
173
|
+
}
|
|
174
|
+
),
|
|
175
|
+
getLeafColumns: memo(
|
|
176
|
+
() => [instance._getOrderColumnsFn()],
|
|
177
|
+
orderColumns => {
|
|
178
|
+
if (column.columns?.length) {
|
|
179
|
+
let leafColumns = column.columns.flatMap(column =>
|
|
180
|
+
column.getLeafColumns()
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
return orderColumns(leafColumns)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return [column as Column<TGenerics>]
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
key: 'column.getLeafColumns',
|
|
190
|
+
debug: () =>
|
|
191
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
192
|
+
}
|
|
193
|
+
),
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
column = instance._features.reduce((obj, feature) => {
|
|
197
|
+
return Object.assign(obj, feature.createColumn?.(column, instance))
|
|
198
|
+
}, column)
|
|
199
|
+
|
|
200
|
+
// Yes, we have to convert instance to uknown, because we know more than the compiler here.
|
|
201
|
+
return column as Column<TGenerics>
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
getAllColumns: memo(
|
|
205
|
+
() => [instance.getColumnDefs()],
|
|
206
|
+
columnDefs => {
|
|
207
|
+
const recurseColumns = (
|
|
208
|
+
columnDefs: ColumnDef<TGenerics>[],
|
|
209
|
+
parent?: Column<TGenerics>,
|
|
210
|
+
depth = 0
|
|
211
|
+
): Column<TGenerics>[] => {
|
|
212
|
+
return columnDefs.map(columnDef => {
|
|
213
|
+
const column = instance.createColumn(columnDef, depth, parent)
|
|
214
|
+
|
|
215
|
+
column.columns = columnDef.columns
|
|
216
|
+
? recurseColumns(columnDef.columns, column, depth + 1)
|
|
217
|
+
: []
|
|
218
|
+
|
|
219
|
+
return column
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return recurseColumns(columnDefs)
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
key: 'getAllColumns',
|
|
227
|
+
debug: () =>
|
|
228
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
229
|
+
}
|
|
230
|
+
),
|
|
231
|
+
|
|
232
|
+
getAllFlatColumns: memo(
|
|
233
|
+
() => [instance.getAllColumns()],
|
|
234
|
+
allColumns => {
|
|
235
|
+
return allColumns.flatMap(column => {
|
|
236
|
+
return column.getFlatColumns()
|
|
237
|
+
})
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
key: 'getAllFlatColumns',
|
|
241
|
+
debug: () =>
|
|
242
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
243
|
+
}
|
|
244
|
+
),
|
|
245
|
+
|
|
246
|
+
getAllFlatColumnsById: memo(
|
|
247
|
+
() => [instance.getAllFlatColumns()],
|
|
248
|
+
flatColumns => {
|
|
249
|
+
return flatColumns.reduce((acc, column) => {
|
|
250
|
+
acc[column.id] = column
|
|
251
|
+
return acc
|
|
252
|
+
}, {} as Record<string, Column<TGenerics>>)
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
key: 'getAllFlatColumnsById',
|
|
256
|
+
debug: () =>
|
|
257
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
258
|
+
}
|
|
259
|
+
),
|
|
260
|
+
|
|
261
|
+
getAllLeafColumns: memo(
|
|
262
|
+
() => [instance.getAllColumns(), instance._getOrderColumnsFn()],
|
|
263
|
+
(allColumns, orderColumns) => {
|
|
264
|
+
let leafColumns = allColumns.flatMap(column =>
|
|
265
|
+
column.getLeafColumns()
|
|
266
|
+
)
|
|
267
|
+
return orderColumns(leafColumns)
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
key: 'getAllLeafColumns',
|
|
271
|
+
debug: () =>
|
|
272
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
273
|
+
}
|
|
274
|
+
),
|
|
275
|
+
|
|
276
|
+
getColumn: columnId => {
|
|
277
|
+
const column = instance.getAllFlatColumnsById()[columnId]
|
|
278
|
+
|
|
279
|
+
if (!column) {
|
|
280
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
281
|
+
console.warn(`[Table] Column with id ${columnId} does not exist.`)
|
|
282
|
+
}
|
|
283
|
+
throw new Error()
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return column
|
|
287
|
+
},
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
}
|
|
@@ -2,8 +2,7 @@ import { RowModel } from '..'
|
|
|
2
2
|
import {
|
|
3
3
|
Getter,
|
|
4
4
|
OnChangeFn,
|
|
5
|
-
|
|
6
|
-
PartialGenerics,
|
|
5
|
+
TableGenerics,
|
|
7
6
|
PropGetterValue,
|
|
8
7
|
TableInstance,
|
|
9
8
|
Row,
|
|
@@ -26,7 +25,7 @@ export type ExpandedRow = {
|
|
|
26
25
|
) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
export type ExpandedOptions<TGenerics extends
|
|
28
|
+
export type ExpandedOptions<TGenerics extends TableGenerics> = {
|
|
30
29
|
onExpandedChange?: OnChangeFn<ExpandedState>
|
|
31
30
|
autoResetExpanded?: boolean
|
|
32
31
|
enableExpanded?: boolean
|
|
@@ -45,7 +44,7 @@ export type ToggleExpandedProps = {
|
|
|
45
44
|
onClick?: (event: unknown) => void
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
export type ExpandedInstance<TGenerics extends
|
|
47
|
+
export type ExpandedInstance<TGenerics extends TableGenerics> = {
|
|
49
48
|
queueResetExpanded: () => void
|
|
50
49
|
setExpanded: (updater: Updater<ExpandedState>) => void
|
|
51
50
|
toggleRowExpanded: (rowId: string, expanded?: boolean) => void
|
|
@@ -78,7 +77,7 @@ export const Expanding = {
|
|
|
78
77
|
}
|
|
79
78
|
},
|
|
80
79
|
|
|
81
|
-
getDefaultOptions: <TGenerics extends
|
|
80
|
+
getDefaultOptions: <TGenerics extends TableGenerics>(
|
|
82
81
|
instance: TableInstance<TGenerics>
|
|
83
82
|
): ExpandedOptions<TGenerics> => {
|
|
84
83
|
return {
|
|
@@ -89,7 +88,7 @@ export const Expanding = {
|
|
|
89
88
|
}
|
|
90
89
|
},
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
93
92
|
instance: TableInstance<TGenerics>
|
|
94
93
|
): ExpandedInstance<TGenerics> => {
|
|
95
94
|
let registered = false
|
|
@@ -291,7 +290,7 @@ export const Expanding = {
|
|
|
291
290
|
}
|
|
292
291
|
},
|
|
293
292
|
|
|
294
|
-
createRow: <TGenerics extends
|
|
293
|
+
createRow: <TGenerics extends TableGenerics>(
|
|
295
294
|
row: Row<TGenerics>,
|
|
296
295
|
instance: TableInstance<TGenerics>
|
|
297
296
|
): ExpandedRow => {
|
package/src/features/Filters.ts
CHANGED
|
@@ -3,8 +3,7 @@ import { BuiltInFilterFn, filterFns } from '../filterFns'
|
|
|
3
3
|
import {
|
|
4
4
|
Column,
|
|
5
5
|
OnChangeFn,
|
|
6
|
-
|
|
7
|
-
PartialGenerics,
|
|
6
|
+
TableGenerics,
|
|
8
7
|
TableInstance,
|
|
9
8
|
Row,
|
|
10
9
|
Updater,
|
|
@@ -35,28 +34,28 @@ export type ColumnFilter = {
|
|
|
35
34
|
A filter function is any function that takes an array of rows and returns an array of rows. Because filter functions can be used for both column and global filters, they are passed an array of columnIds to filter on.
|
|
36
35
|
*/
|
|
37
36
|
|
|
38
|
-
export type FilterFn<TGenerics extends
|
|
37
|
+
export type FilterFn<TGenerics extends TableGenerics> = {
|
|
39
38
|
(rows: Row<TGenerics>[], columnIds: string[], filterValue: any): any
|
|
40
39
|
autoRemove?: ColumnFilterAutoRemoveTestFn<TGenerics>
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
export type ColumnFilterAutoRemoveTestFn<TGenerics extends
|
|
42
|
+
export type ColumnFilterAutoRemoveTestFn<TGenerics extends TableGenerics> = (
|
|
44
43
|
value: unknown,
|
|
45
44
|
column?: Column<TGenerics>
|
|
46
45
|
) => boolean
|
|
47
46
|
|
|
48
|
-
export type CustomFilterFns<TGenerics extends
|
|
47
|
+
export type CustomFilterFns<TGenerics extends TableGenerics> = Record<
|
|
49
48
|
string,
|
|
50
49
|
FilterFn<TGenerics>
|
|
51
50
|
>
|
|
52
51
|
|
|
53
|
-
export type FilterFnOption<TGenerics extends
|
|
52
|
+
export type FilterFnOption<TGenerics extends TableGenerics> =
|
|
54
53
|
| 'auto'
|
|
55
54
|
| BuiltInFilterFn
|
|
56
55
|
| keyof TGenerics['FilterFns']
|
|
57
56
|
| FilterFn<TGenerics>
|
|
58
57
|
|
|
59
|
-
export type FiltersColumnDef<TGenerics extends
|
|
58
|
+
export type FiltersColumnDef<TGenerics extends TableGenerics> = {
|
|
60
59
|
filterFn?: FilterFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
61
60
|
enableAllFilters?: boolean
|
|
62
61
|
enableColumnFilter?: boolean
|
|
@@ -66,7 +65,7 @@ export type FiltersColumnDef<TGenerics extends AnyGenerics> = {
|
|
|
66
65
|
defaultCanGlobalFilter?: boolean
|
|
67
66
|
}
|
|
68
67
|
|
|
69
|
-
export type FiltersColumn<TGenerics extends
|
|
68
|
+
export type FiltersColumn<TGenerics extends TableGenerics> = {
|
|
70
69
|
filterFn: FilterFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
71
70
|
getCanColumnFilter: () => boolean
|
|
72
71
|
getCanGlobalFilter: () => boolean
|
|
@@ -79,7 +78,7 @@ export type FiltersColumn<TGenerics extends AnyGenerics> = {
|
|
|
79
78
|
getPreFilteredMinMaxValues: () => [any, any]
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
export type FiltersOptions<TGenerics extends
|
|
81
|
+
export type FiltersOptions<TGenerics extends TableGenerics> = {
|
|
83
82
|
filterFromLeafRows?: boolean
|
|
84
83
|
filterFns?: TGenerics['FilterFns']
|
|
85
84
|
enableFilters?: boolean
|
|
@@ -101,7 +100,7 @@ export type FiltersOptions<TGenerics extends AnyGenerics> = {
|
|
|
101
100
|
getColumnCanGlobalFilterFn?: (column: Column<TGenerics>) => boolean
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
export type FiltersInstance<TGenerics extends
|
|
103
|
+
export type FiltersInstance<TGenerics extends TableGenerics> = {
|
|
105
104
|
queueResetFilters: () => void
|
|
106
105
|
getColumnAutoFilterFn: (columnId: string) => FilterFn<TGenerics> | undefined
|
|
107
106
|
|
|
@@ -136,7 +135,7 @@ export type FiltersInstance<TGenerics extends AnyGenerics> = {
|
|
|
136
135
|
|
|
137
136
|
export const Filters = {
|
|
138
137
|
getDefaultColumn: <
|
|
139
|
-
TGenerics extends
|
|
138
|
+
TGenerics extends TableGenerics
|
|
140
139
|
>(): FiltersColumnDef<TGenerics> => {
|
|
141
140
|
return {
|
|
142
141
|
filterFn: 'auto',
|
|
@@ -152,7 +151,7 @@ export const Filters = {
|
|
|
152
151
|
}
|
|
153
152
|
},
|
|
154
153
|
|
|
155
|
-
getDefaultOptions: <TGenerics extends
|
|
154
|
+
getDefaultOptions: <TGenerics extends TableGenerics>(
|
|
156
155
|
instance: TableInstance<TGenerics>
|
|
157
156
|
): FiltersOptions<TGenerics> => {
|
|
158
157
|
return {
|
|
@@ -172,7 +171,7 @@ export const Filters = {
|
|
|
172
171
|
}
|
|
173
172
|
},
|
|
174
173
|
|
|
175
|
-
createColumn: <TGenerics extends
|
|
174
|
+
createColumn: <TGenerics extends TableGenerics>(
|
|
176
175
|
column: Column<TGenerics>,
|
|
177
176
|
instance: TableInstance<TGenerics>
|
|
178
177
|
): FiltersColumn<TGenerics> => {
|
|
@@ -231,7 +230,7 @@ export const Filters = {
|
|
|
231
230
|
}
|
|
232
231
|
},
|
|
233
232
|
|
|
234
|
-
|
|
233
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
235
234
|
instance: TableInstance<TGenerics>
|
|
236
235
|
): FiltersInstance<TGenerics> => {
|
|
237
236
|
let registered = false
|
|
@@ -498,7 +497,7 @@ export const Filters = {
|
|
|
498
497
|
},
|
|
499
498
|
}
|
|
500
499
|
|
|
501
|
-
export function shouldAutoRemoveFilter<TGenerics extends
|
|
500
|
+
export function shouldAutoRemoveFilter<TGenerics extends TableGenerics>(
|
|
502
501
|
filterFn?: FilterFn<TGenerics>,
|
|
503
502
|
value?: any,
|
|
504
503
|
column?: Column<TGenerics>
|
package/src/features/Grouping.ts
CHANGED
|
@@ -9,10 +9,9 @@ import {
|
|
|
9
9
|
TableInstance,
|
|
10
10
|
Row,
|
|
11
11
|
Updater,
|
|
12
|
-
PartialGenerics,
|
|
13
12
|
Renderable,
|
|
14
13
|
UseRenderer,
|
|
15
|
-
|
|
14
|
+
TableGenerics,
|
|
16
15
|
} from '../types'
|
|
17
16
|
import {
|
|
18
17
|
functionalUpdate,
|
|
@@ -25,17 +24,17 @@ import {
|
|
|
25
24
|
|
|
26
25
|
export type GroupingState = string[]
|
|
27
26
|
|
|
28
|
-
export type AggregationFn<TGenerics extends
|
|
27
|
+
export type AggregationFn<TGenerics extends TableGenerics> = (
|
|
29
28
|
getLeafValues: () => TGenerics['Row'][],
|
|
30
29
|
getChildValues: () => TGenerics['Row'][]
|
|
31
30
|
) => any
|
|
32
31
|
|
|
33
|
-
export type CustomAggregationFns<TGenerics extends
|
|
32
|
+
export type CustomAggregationFns<TGenerics extends TableGenerics> = Record<
|
|
34
33
|
string,
|
|
35
34
|
AggregationFn<TGenerics>
|
|
36
35
|
>
|
|
37
36
|
|
|
38
|
-
export type AggregationFnOption<TGenerics extends
|
|
37
|
+
export type AggregationFnOption<TGenerics extends TableGenerics> =
|
|
39
38
|
| 'auto'
|
|
40
39
|
| BuiltInAggregationFn
|
|
41
40
|
| keyof TGenerics['AggregationFns']
|
|
@@ -45,7 +44,7 @@ export type GroupingTableState = {
|
|
|
45
44
|
grouping: GroupingState
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
export type GroupingColumnDef<TGenerics extends
|
|
47
|
+
export type GroupingColumnDef<TGenerics extends TableGenerics> = {
|
|
49
48
|
aggregationFn?: AggregationFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
50
49
|
aggregateValue?: (columnValue: unknown) => any
|
|
51
50
|
aggregatedCell?: Renderable<
|
|
@@ -62,7 +61,7 @@ export type GroupingColumnDef<TGenerics extends AnyGenerics> = {
|
|
|
62
61
|
defaultCanGroup?: boolean
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
export type GroupingColumn<TGenerics extends
|
|
64
|
+
export type GroupingColumn<TGenerics extends TableGenerics> = {
|
|
66
65
|
aggregationFn?: AggregationFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
67
66
|
getCanGroup: () => boolean
|
|
68
67
|
getIsGrouped: () => boolean
|
|
@@ -79,7 +78,7 @@ export type GroupingRow = {
|
|
|
79
78
|
getIsGrouped: () => boolean
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
export type GroupingCell<TGenerics extends
|
|
81
|
+
export type GroupingCell<TGenerics extends TableGenerics> = {
|
|
83
82
|
getIsGrouped: () => boolean
|
|
84
83
|
getIsPlaceholder: () => boolean
|
|
85
84
|
getIsAggregated: () => boolean
|
|
@@ -93,7 +92,7 @@ export type ColumnDefaultOptions = {
|
|
|
93
92
|
enableGrouping: boolean
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
export type GroupingOptions<TGenerics extends
|
|
95
|
+
export type GroupingOptions<TGenerics extends TableGenerics> = {
|
|
97
96
|
aggregationFns?: TGenerics['AggregationFns']
|
|
98
97
|
onGroupingChange?: OnChangeFn<GroupingState>
|
|
99
98
|
autoResetGrouping?: boolean
|
|
@@ -113,7 +112,7 @@ export type ToggleGroupingProps = {
|
|
|
113
112
|
onClick?: (event: unknown) => void
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
export type GroupingInstance<TGenerics extends
|
|
115
|
+
export type GroupingInstance<TGenerics extends TableGenerics> = {
|
|
117
116
|
queueResetGrouping: () => void
|
|
118
117
|
getColumnAutoAggregationFn: (
|
|
119
118
|
columnId: string
|
|
@@ -141,7 +140,7 @@ export type GroupingInstance<TGenerics extends AnyGenerics> = {
|
|
|
141
140
|
|
|
142
141
|
export const Grouping = {
|
|
143
142
|
getDefaultColumn: <
|
|
144
|
-
TGenerics extends
|
|
143
|
+
TGenerics extends TableGenerics
|
|
145
144
|
>(): GroupingColumnDef<TGenerics> => {
|
|
146
145
|
return {
|
|
147
146
|
aggregationFn: 'auto',
|
|
@@ -154,7 +153,7 @@ export const Grouping = {
|
|
|
154
153
|
}
|
|
155
154
|
},
|
|
156
155
|
|
|
157
|
-
getDefaultOptions: <TGenerics extends
|
|
156
|
+
getDefaultOptions: <TGenerics extends TableGenerics>(
|
|
158
157
|
instance: TableInstance<TGenerics>
|
|
159
158
|
): GroupingOptions<TGenerics> => {
|
|
160
159
|
return {
|
|
@@ -164,7 +163,7 @@ export const Grouping = {
|
|
|
164
163
|
}
|
|
165
164
|
},
|
|
166
165
|
|
|
167
|
-
createColumn: <TGenerics extends
|
|
166
|
+
createColumn: <TGenerics extends TableGenerics>(
|
|
168
167
|
column: Column<TGenerics>,
|
|
169
168
|
instance: TableInstance<TGenerics>
|
|
170
169
|
): GroupingColumn<TGenerics> => {
|
|
@@ -179,7 +178,7 @@ export const Grouping = {
|
|
|
179
178
|
}
|
|
180
179
|
},
|
|
181
180
|
|
|
182
|
-
|
|
181
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
183
182
|
instance: TableInstance<TGenerics>
|
|
184
183
|
): GroupingInstance<TGenerics> => {
|
|
185
184
|
let registered = false
|
|
@@ -316,7 +315,7 @@ export const Grouping = {
|
|
|
316
315
|
}
|
|
317
316
|
},
|
|
318
317
|
|
|
319
|
-
createRow: <TGenerics extends
|
|
318
|
+
createRow: <TGenerics extends TableGenerics>(
|
|
320
319
|
row: Row<TGenerics>,
|
|
321
320
|
instance: TableInstance<TGenerics>
|
|
322
321
|
): GroupingRow => {
|
|
@@ -325,7 +324,7 @@ export const Grouping = {
|
|
|
325
324
|
}
|
|
326
325
|
},
|
|
327
326
|
|
|
328
|
-
createCell: <TGenerics extends
|
|
327
|
+
createCell: <TGenerics extends TableGenerics>(
|
|
329
328
|
cell: Cell<TGenerics>,
|
|
330
329
|
column: Column<TGenerics>,
|
|
331
330
|
row: Row<TGenerics>,
|
|
@@ -355,7 +354,7 @@ export const Grouping = {
|
|
|
355
354
|
}
|
|
356
355
|
},
|
|
357
356
|
|
|
358
|
-
orderColumns: <TGenerics extends
|
|
357
|
+
orderColumns: <TGenerics extends TableGenerics>(
|
|
359
358
|
leafColumns: Column<TGenerics>[],
|
|
360
359
|
grouping: string[],
|
|
361
360
|
groupedColumnMode?: GroupingColumnMode
|