@tanstack/table-core 8.0.0-alpha.67 → 8.0.0-alpha.70
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/aggregationFns.js +25 -37
- package/build/cjs/aggregationFns.js.map +1 -1
- package/build/cjs/core.js +167 -46
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +24 -40
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Cells.js +28 -34
- package/build/cjs/features/Cells.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +102 -116
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js +52 -79
- package/build/cjs/features/Columns.js.map +1 -1
- package/build/cjs/features/Expanding.js +49 -58
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +98 -193
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +53 -71
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +109 -165
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js +31 -43
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +79 -82
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +71 -125
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +93 -112
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +32 -22
- package/build/cjs/features/Rows.js.map +1 -1
- package/build/cjs/features/Sorting.js +54 -73
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +47 -86
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js +48 -72
- package/build/cjs/filterFns.js.map +1 -1
- package/build/cjs/index.js +13 -13
- package/build/cjs/sortingFns.js +21 -21
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +49 -55
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +98 -0
- package/build/cjs/utils/getCoreRowModel.js.map +1 -0
- package/build/cjs/utils/getExpandedRowModel.js +17 -21
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedMinMaxValues.js +48 -0
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -0
- package/build/cjs/utils/getFacetedRowModel.js +50 -0
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -0
- package/build/cjs/utils/getFacetedUniqueValues.js +48 -0
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -0
- package/build/cjs/utils/getFilteredRowModel.js +130 -0
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
- package/build/cjs/utils/getGroupedRowModel.js +126 -136
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +39 -39
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +112 -0
- package/build/cjs/utils/getSortedRowModel.js.map +1 -0
- package/build/cjs/utils.js +36 -207
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +1778 -2347
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +421 -481
- package/build/types/core.d.ts +3 -5
- package/build/types/features/Cells.d.ts +1 -1
- package/build/types/features/ColumnSizing.d.ts +2 -2
- package/build/types/features/Columns.d.ts +1 -1
- package/build/types/features/Expanding.d.ts +1 -1
- package/build/types/features/Filters.d.ts +12 -7
- package/build/types/features/Grouping.d.ts +5 -4
- package/build/types/features/Ordering.d.ts +1 -1
- package/build/types/features/Pagination.d.ts +4 -4
- package/build/types/features/Pinning.d.ts +1 -1
- package/build/types/features/RowSelection.d.ts +1 -1
- package/build/types/features/Rows.d.ts +4 -3
- package/build/types/features/Sorting.d.ts +2 -1
- package/build/types/features/Visibility.d.ts +1 -0
- package/build/types/index.d.ts +6 -4
- package/build/types/types.d.ts +3 -13
- package/build/types/utils/filterRowsUtils.d.ts +3 -3
- package/build/types/utils/getCoreRowModel.d.ts +2 -0
- package/build/types/utils/getFacetedMinMaxValues.d.ts +2 -0
- package/build/types/utils/getFacetedRowModel.d.ts +2 -0
- package/build/types/utils/getFacetedUniqueValues.d.ts +2 -0
- package/build/types/utils/{getCoreRowModelSync.d.ts → getFilteredRowModel.d.ts} +1 -1
- package/build/types/utils/getGroupedRowModel.d.ts +1 -1
- package/build/types/utils/getSortedRowModel.d.ts +2 -0
- package/build/types/utils.d.ts +1 -17
- package/build/umd/index.development.js +1779 -2350
- 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 +197 -45
- package/src/features/Cells.ts +7 -11
- package/src/features/ColumnSizing.ts +27 -19
- package/src/features/Columns.ts +4 -8
- package/src/features/Expanding.ts +5 -3
- package/src/features/Filters.ts +105 -162
- package/src/features/Grouping.ts +21 -23
- package/src/features/Ordering.ts +5 -3
- package/src/features/Pagination.ts +32 -19
- package/src/features/Pinning.ts +13 -7
- package/src/features/RowSelection.ts +5 -3
- package/src/features/Rows.ts +21 -6
- package/src/features/Sorting.ts +14 -12
- package/src/features/Visibility.ts +7 -0
- package/src/filterFns.ts +9 -9
- package/src/index.ts +12 -4
- package/src/sortingFns.ts +11 -11
- package/src/types.ts +3 -16
- package/src/utils/filterRowsUtils.ts +47 -68
- package/src/utils/{getCoreRowModelSync.ts → getCoreRowModel.ts} +2 -8
- package/src/utils/getFacetedMinMaxValues.ts +37 -0
- package/src/utils/getFacetedRowModel.ts +50 -0
- package/src/utils/getFacetedUniqueValues.ts +37 -0
- package/src/utils/{getFilteredRowModelSync.ts → getFilteredRowModel.ts} +29 -20
- package/src/utils/getGroupedRowModel.ts +52 -61
- package/src/utils/{getSortedRowModelSync.ts → getSortedRowModel.ts} +3 -3
- package/src/utils.ts +28 -236
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/utils/getCoreRowModelAsync.js +0 -125
- package/build/cjs/utils/getCoreRowModelAsync.js.map +0 -1
- package/build/cjs/utils/getCoreRowModelSync.js +0 -102
- package/build/cjs/utils/getCoreRowModelSync.js.map +0 -1
- package/build/cjs/utils/getFilteredRowModelSync.js +0 -125
- package/build/cjs/utils/getFilteredRowModelSync.js.map +0 -1
- package/build/cjs/utils/getSortedRowModelSync.js +0 -118
- package/build/cjs/utils/getSortedRowModelSync.js.map +0 -1
- package/build/types/utils/getCoreRowModelAsync.d.ts +0 -4
- package/build/types/utils/getFilteredRowModelAsync.d.ts +0 -4
- package/build/types/utils/getFilteredRowModelSync.d.ts +0 -2
- package/build/types/utils/getSortedRowModelAsync.d.ts +0 -13
- package/build/types/utils/getSortedRowModelSync.d.ts +0 -2
- package/src/utils/getCoreRowModelAsync.ts +0 -104
- package/src/utils/getFilteredRowModelAsync.ts +0 -157
- package/src/utils/getSortedRowModelAsync.ts +0 -200
|
@@ -53,7 +53,7 @@ export type RowSelectionInstance<TGenerics extends TableGenerics> = {
|
|
|
53
53
|
getToggleAllRowsSelectedHandler: () => (event: unknown) => void
|
|
54
54
|
getToggleAllPageRowsSelectedHandler: () => (event: unknown) => void
|
|
55
55
|
setRowSelection: (updater: Updater<RowSelectionState>) => void
|
|
56
|
-
resetRowSelection: () => void
|
|
56
|
+
resetRowSelection: (defaultState?: boolean) => void
|
|
57
57
|
getIsAllRowsSelected: () => boolean
|
|
58
58
|
getIsAllPageRowsSelected: () => boolean
|
|
59
59
|
getIsSomeRowsSelected: () => boolean
|
|
@@ -96,8 +96,10 @@ export const RowSelection: TableFeature = {
|
|
|
96
96
|
return {
|
|
97
97
|
setRowSelection: updater =>
|
|
98
98
|
instance.options.onRowSelectionChange?.(updater),
|
|
99
|
-
resetRowSelection:
|
|
100
|
-
instance.setRowSelection(
|
|
99
|
+
resetRowSelection: defaultState =>
|
|
100
|
+
instance.setRowSelection(
|
|
101
|
+
defaultState ? {} : instance.initialState.rowSelection ?? {}
|
|
102
|
+
),
|
|
101
103
|
toggleAllRowsSelected: value => {
|
|
102
104
|
instance.setRowSelection(old => {
|
|
103
105
|
value =
|
package/src/features/Rows.ts
CHANGED
|
@@ -12,7 +12,8 @@ export type CoreRow<TGenerics extends TableGenerics> = {
|
|
|
12
12
|
index: number
|
|
13
13
|
original?: TGenerics['Row']
|
|
14
14
|
depth: number
|
|
15
|
-
|
|
15
|
+
valuesCache: Record<string, any>
|
|
16
|
+
getValue: (columnId: string) => any
|
|
16
17
|
subRows: Row<TGenerics>[]
|
|
17
18
|
getLeafRows: () => Row<TGenerics>[]
|
|
18
19
|
originalSubRows?: TGenerics['Row'][]
|
|
@@ -44,7 +45,7 @@ export type RowsInstance<TGenerics extends TableGenerics> = {
|
|
|
44
45
|
original: TGenerics['Row'] | undefined,
|
|
45
46
|
rowIndex: number,
|
|
46
47
|
depth: number,
|
|
47
|
-
|
|
48
|
+
subRows?: Row<TGenerics>[]
|
|
48
49
|
) => Row<TGenerics>
|
|
49
50
|
getCoreRowModel: () => RowModel<TGenerics>
|
|
50
51
|
_getCoreRowModel?: () => RowModel<TGenerics>
|
|
@@ -73,20 +74,34 @@ export const Rows = {
|
|
|
73
74
|
) =>
|
|
74
75
|
instance.options.getRowId?.(row, index, parent) ??
|
|
75
76
|
`${parent ? [parent.id, index].join('.') : index}`,
|
|
76
|
-
createRow: (id, original, rowIndex, depth,
|
|
77
|
+
createRow: (id, original, rowIndex, depth, subRows) => {
|
|
77
78
|
let row: CoreRow<TGenerics> = {
|
|
78
79
|
id,
|
|
79
80
|
index: rowIndex,
|
|
80
81
|
original,
|
|
81
82
|
depth,
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
valuesCache: {},
|
|
84
|
+
getValue: columnId => {
|
|
85
|
+
if (row.valuesCache.hasOwnProperty(columnId)) {
|
|
86
|
+
return row.valuesCache[columnId]
|
|
87
|
+
}
|
|
88
|
+
const column = instance.getColumn(columnId)
|
|
89
|
+
if (!column.accessorFn) {
|
|
90
|
+
throw new Error()
|
|
91
|
+
}
|
|
92
|
+
row.valuesCache[columnId] = column.accessorFn(
|
|
93
|
+
row.original,
|
|
94
|
+
rowIndex
|
|
95
|
+
)
|
|
96
|
+
return row.valuesCache[columnId]
|
|
97
|
+
},
|
|
98
|
+
subRows: subRows ?? [],
|
|
84
99
|
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
85
100
|
}
|
|
86
101
|
|
|
87
102
|
for (let i = 0; i < instance._features.length; i++) {
|
|
88
103
|
const feature = instance._features[i]
|
|
89
|
-
Object.assign(row, feature
|
|
104
|
+
Object.assign(row, feature?.createRow?.(row, instance))
|
|
90
105
|
}
|
|
91
106
|
|
|
92
107
|
return row as Row<TGenerics>
|
package/src/features/Sorting.ts
CHANGED
|
@@ -62,7 +62,7 @@ export type SortingColumn<TGenerics extends TableGenerics> = {
|
|
|
62
62
|
getCanMultiSort: () => boolean
|
|
63
63
|
getSortIndex: () => number
|
|
64
64
|
getIsSorted: () => false | SortDirection
|
|
65
|
-
|
|
65
|
+
clearSorting: () => void
|
|
66
66
|
toggleSorting: (desc?: boolean, isMulti?: boolean) => void
|
|
67
67
|
getToggleSortingHandler: () => undefined | ((event: unknown) => void)
|
|
68
68
|
}
|
|
@@ -85,6 +85,7 @@ export type SortingOptions<TGenerics extends TableGenerics> = {
|
|
|
85
85
|
|
|
86
86
|
export type SortingInstance<TGenerics extends TableGenerics> = {
|
|
87
87
|
setSorting: (updater: Updater<SortingState>) => void
|
|
88
|
+
resetSorting: (defaultState?: boolean) => void
|
|
88
89
|
getPreSortedRowModel: () => RowModel<TGenerics>
|
|
89
90
|
getSortedRowModel: () => RowModel<TGenerics>
|
|
90
91
|
_getSortedRowModel?: () => RowModel<TGenerics>
|
|
@@ -130,7 +131,7 @@ export const Sorting: TableFeature = {
|
|
|
130
131
|
let isString = false
|
|
131
132
|
|
|
132
133
|
for (const row of firstRows) {
|
|
133
|
-
const value = row?.
|
|
134
|
+
const value = row?.getValue(column.id)
|
|
134
135
|
|
|
135
136
|
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
136
137
|
return sortingFns.datetime
|
|
@@ -154,7 +155,7 @@ export const Sorting: TableFeature = {
|
|
|
154
155
|
getAutoSortDir: () => {
|
|
155
156
|
const firstRow = instance.getFilteredRowModel().flatRows[0]
|
|
156
157
|
|
|
157
|
-
const value = firstRow?.
|
|
158
|
+
const value = firstRow?.getValue(column.id)
|
|
158
159
|
|
|
159
160
|
if (typeof value === 'string') {
|
|
160
161
|
return 'asc'
|
|
@@ -304,14 +305,11 @@ export const Sorting: TableFeature = {
|
|
|
304
305
|
getSortIndex: () =>
|
|
305
306
|
instance.getState().sorting?.findIndex(d => d.id === column.id) ?? -1,
|
|
306
307
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
} else {
|
|
313
|
-
instance.setSorting(instance.initialState?.sorting ?? [])
|
|
314
|
-
}
|
|
308
|
+
clearSorting: () => {
|
|
309
|
+
//clear sorting for just 1 column
|
|
310
|
+
instance.setSorting(old =>
|
|
311
|
+
old?.length ? old.filter(d => d.id !== column.id) : []
|
|
312
|
+
)
|
|
315
313
|
},
|
|
316
314
|
|
|
317
315
|
getToggleSortingHandler: () => {
|
|
@@ -338,7 +336,11 @@ export const Sorting: TableFeature = {
|
|
|
338
336
|
|
|
339
337
|
return {
|
|
340
338
|
setSorting: updater => instance.options.onSortingChange?.(updater),
|
|
341
|
-
|
|
339
|
+
resetSorting: defaultState => {
|
|
340
|
+
instance.setSorting(
|
|
341
|
+
defaultState ? [] : instance.initialState?.sorting ?? []
|
|
342
|
+
)
|
|
343
|
+
},
|
|
342
344
|
getPreSortedRowModel: () => instance.getFilteredRowModel(),
|
|
343
345
|
getSortedRowModel: () => {
|
|
344
346
|
if (
|
|
@@ -32,6 +32,7 @@ export type VisibilityInstance<TGenerics extends TableGenerics> = {
|
|
|
32
32
|
getRightVisibleLeafColumns: () => Column<TGenerics>[]
|
|
33
33
|
getCenterVisibleLeafColumns: () => Column<TGenerics>[]
|
|
34
34
|
setColumnVisibility: (updater: Updater<VisibilityState>) => void
|
|
35
|
+
resetColumnVisibility: (defaultState?: boolean) => void
|
|
35
36
|
toggleAllColumnsVisible: (value?: boolean) => void
|
|
36
37
|
getIsAllColumnsVisible: () => boolean
|
|
37
38
|
getIsSomeColumnsVisible: () => boolean
|
|
@@ -202,6 +203,12 @@ export const Visibility: TableFeature = {
|
|
|
202
203
|
setColumnVisibility: updater =>
|
|
203
204
|
instance.options.onColumnVisibilityChange?.(updater),
|
|
204
205
|
|
|
206
|
+
resetColumnVisibility: defaultState => {
|
|
207
|
+
instance.setColumnVisibility(
|
|
208
|
+
defaultState ? {} : instance.initialState.columnVisibility ?? {}
|
|
209
|
+
)
|
|
210
|
+
},
|
|
211
|
+
|
|
205
212
|
toggleAllColumnsVisible: value => {
|
|
206
213
|
value = value ?? !instance.getIsAllColumnsVisible()
|
|
207
214
|
|
package/src/filterFns.ts
CHANGED
|
@@ -6,7 +6,7 @@ const includesString: FilterFn<any> = (
|
|
|
6
6
|
filterValue: string
|
|
7
7
|
) => {
|
|
8
8
|
const search = filterValue.toLowerCase()
|
|
9
|
-
return row.
|
|
9
|
+
return row.getValue(columnId).toLowerCase().includes(search)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
includesString.autoRemove = (val: any) => testFalsey(val)
|
|
@@ -16,7 +16,7 @@ const includesStringSensitive: FilterFn<any> = (
|
|
|
16
16
|
columnId: string,
|
|
17
17
|
filterValue: string
|
|
18
18
|
) => {
|
|
19
|
-
return row.
|
|
19
|
+
return row.getValue(columnId).includes(filterValue)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
includesStringSensitive.autoRemove = (val: any) => testFalsey(val)
|
|
@@ -26,7 +26,7 @@ const equalsString: FilterFn<any> = (
|
|
|
26
26
|
columnId: string,
|
|
27
27
|
filterValue: string
|
|
28
28
|
) => {
|
|
29
|
-
return row.
|
|
29
|
+
return row.getValue(columnId).toLowerCase() === filterValue.toLowerCase()
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
equalsString.autoRemove = (val: any) => testFalsey(val)
|
|
@@ -36,7 +36,7 @@ const arrIncludes: FilterFn<any> = (
|
|
|
36
36
|
columnId: string,
|
|
37
37
|
filterValue: unknown
|
|
38
38
|
) => {
|
|
39
|
-
return row.
|
|
39
|
+
return row.getValue(columnId).includes(filterValue)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
arrIncludes.autoRemove = (val: any) => testFalsey(val) || !val?.length
|
|
@@ -46,7 +46,7 @@ const arrIncludesAll: FilterFn<any> = (
|
|
|
46
46
|
columnId: string,
|
|
47
47
|
filterValue: unknown[]
|
|
48
48
|
) => {
|
|
49
|
-
return !filterValue.some(val => !row.
|
|
49
|
+
return !filterValue.some(val => !row.getValue(columnId).includes(val))
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
arrIncludesAll.autoRemove = (val: any) => testFalsey(val) || !val?.length
|
|
@@ -56,13 +56,13 @@ const arrIncludesSome: FilterFn<any> = (
|
|
|
56
56
|
columnId: string,
|
|
57
57
|
filterValue: unknown[]
|
|
58
58
|
) => {
|
|
59
|
-
return filterValue.some(val => row.
|
|
59
|
+
return filterValue.some(val => row.getValue(columnId).includes(val))
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
arrIncludesSome.autoRemove = (val: any) => testFalsey(val) || !val?.length
|
|
63
63
|
|
|
64
64
|
const equals: FilterFn<any> = (row, columnId: string, filterValue: unknown) => {
|
|
65
|
-
return row.
|
|
65
|
+
return row.getValue(columnId) === filterValue
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
equals.autoRemove = (val: any) => testFalsey(val)
|
|
@@ -72,7 +72,7 @@ const weakEquals: FilterFn<any> = (
|
|
|
72
72
|
columnId: string,
|
|
73
73
|
filterValue: unknown
|
|
74
74
|
) => {
|
|
75
|
-
return row.
|
|
75
|
+
return row.getValue(columnId) == filterValue
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
weakEquals.autoRemove = (val: any) => testFalsey(val)
|
|
@@ -84,7 +84,7 @@ const inNumberRange: FilterFn<any> = (
|
|
|
84
84
|
) => {
|
|
85
85
|
let [min, max] = filterValue
|
|
86
86
|
|
|
87
|
-
const rowValue = row.
|
|
87
|
+
const rowValue = row.getValue(columnId)
|
|
88
88
|
return rowValue >= min && rowValue <= max
|
|
89
89
|
}
|
|
90
90
|
|
package/src/index.ts
CHANGED
|
@@ -15,10 +15,18 @@ export * from './features/Sorting'
|
|
|
15
15
|
export * from './features/Visibility'
|
|
16
16
|
export * from './features/Expanding'
|
|
17
17
|
export * from './utils'
|
|
18
|
-
export * from './utils/
|
|
19
|
-
export * from './utils/
|
|
20
|
-
export * from './utils/
|
|
21
|
-
export * from './utils/
|
|
18
|
+
export * from './utils/getCoreRowModel'
|
|
19
|
+
export * from './utils/getFilteredRowModel'
|
|
20
|
+
export * from './utils/getFacetedRowModel'
|
|
21
|
+
export * from './utils/getFacetedUniqueValues'
|
|
22
|
+
export * from './utils/getFacetedMinMaxValues'
|
|
23
|
+
export * from './utils/getSortedRowModel'
|
|
22
24
|
export * from './utils/getGroupedRowModel'
|
|
23
25
|
export * from './utils/getExpandedRowModel'
|
|
24
26
|
export * from './utils/getPaginationRowModel'
|
|
27
|
+
// Experimental Async
|
|
28
|
+
// export * from './utils/getCoreRowModelAsync'
|
|
29
|
+
// export * from './utils/getFilteredRowModelAsync'
|
|
30
|
+
// export * from './utils/getFacetedRowModelAsync'
|
|
31
|
+
// export * from './utils/getFacetedUniqueValuesAsync'
|
|
32
|
+
// export * from './utils/getFacetedMinMaxValuesAsync'
|
package/src/sortingFns.ts
CHANGED
|
@@ -19,8 +19,8 @@ function alphanumeric<TGenerics extends TableGenerics>(
|
|
|
19
19
|
columnId: string
|
|
20
20
|
) {
|
|
21
21
|
return compareAlphanumeric(
|
|
22
|
-
toString(rowA.
|
|
23
|
-
toString(rowB.
|
|
22
|
+
toString(rowA.getValue(columnId)).toLowerCase(),
|
|
23
|
+
toString(rowB.getValue(columnId)).toLowerCase()
|
|
24
24
|
)
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -30,8 +30,8 @@ function alphanumericCaseSensitive<TGenerics extends TableGenerics>(
|
|
|
30
30
|
columnId: string
|
|
31
31
|
) {
|
|
32
32
|
return compareAlphanumeric(
|
|
33
|
-
toString(rowA.
|
|
34
|
-
toString(rowB.
|
|
33
|
+
toString(rowA.getValue(columnId)),
|
|
34
|
+
toString(rowB.getValue(columnId))
|
|
35
35
|
)
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -90,8 +90,8 @@ function text<TGenerics extends TableGenerics>(
|
|
|
90
90
|
columnId: string
|
|
91
91
|
) {
|
|
92
92
|
return compareBasic(
|
|
93
|
-
toString(rowA.
|
|
94
|
-
toString(rowB.
|
|
93
|
+
toString(rowA.getValue(columnId)).toLowerCase(),
|
|
94
|
+
toString(rowB.getValue(columnId)).toLowerCase()
|
|
95
95
|
)
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -103,8 +103,8 @@ function textCaseSensitive<TGenerics extends TableGenerics>(
|
|
|
103
103
|
columnId: string
|
|
104
104
|
) {
|
|
105
105
|
return compareBasic(
|
|
106
|
-
toString(rowA.
|
|
107
|
-
toString(rowB.
|
|
106
|
+
toString(rowA.getValue(columnId)),
|
|
107
|
+
toString(rowB.getValue(columnId))
|
|
108
108
|
)
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -114,8 +114,8 @@ function datetime<TGenerics extends TableGenerics>(
|
|
|
114
114
|
columnId: string
|
|
115
115
|
) {
|
|
116
116
|
return compareBasic(
|
|
117
|
-
(rowA.
|
|
118
|
-
(rowB.
|
|
117
|
+
(rowA.getValue(columnId) as Date).getTime(),
|
|
118
|
+
(rowB.getValue(columnId) as Date).getTime()
|
|
119
119
|
)
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -124,7 +124,7 @@ function basic<TGenerics extends TableGenerics>(
|
|
|
124
124
|
rowB: Row<TGenerics>,
|
|
125
125
|
columnId: string
|
|
126
126
|
) {
|
|
127
|
-
return compareBasic(rowA.
|
|
127
|
+
return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId))
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// Utils
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreOptions, CoreTableState,
|
|
1
|
+
import { CoreOptions, CoreTableState, CoreInstance } from './core'
|
|
2
2
|
import { ColumnsOptions, CoreColumn, CoreColumnDef } from './features/Columns'
|
|
3
3
|
import {
|
|
4
4
|
VisibilityInstance,
|
|
@@ -107,7 +107,7 @@ export type TableFeature = {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
export type TableInstance<TGenerics extends TableGenerics> =
|
|
110
|
-
|
|
110
|
+
CoreInstance<TGenerics> &
|
|
111
111
|
ColumnsInstance<TGenerics> &
|
|
112
112
|
RowsInstance<TGenerics> &
|
|
113
113
|
CellsInstance<TGenerics> &
|
|
@@ -214,7 +214,7 @@ export type CoreCell<TGenerics extends TableGenerics> = {
|
|
|
214
214
|
id: string
|
|
215
215
|
rowId: string
|
|
216
216
|
columnId: string
|
|
217
|
-
|
|
217
|
+
getValue: () => TGenerics['Value']
|
|
218
218
|
row: Row<TGenerics>
|
|
219
219
|
column: Column<TGenerics>
|
|
220
220
|
renderCell: () => string | null | TGenerics['Rendered']
|
|
@@ -249,17 +249,4 @@ export type HeaderGroup<TGenerics extends TableGenerics> = {
|
|
|
249
249
|
headers: Header<TGenerics>[]
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
export type HeaderRenderProps<THeader> = {
|
|
253
|
-
header: THeader
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export type FooterRenderProps<THeader> = {
|
|
257
|
-
header: THeader
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export type CellRenderProps<TCell, TRow> = {
|
|
261
|
-
cell: TCell
|
|
262
|
-
row: TRow
|
|
263
|
-
}
|
|
264
|
-
|
|
265
252
|
export type NoInfer<A extends any> = [A][A extends any ? 0 : never]
|
|
@@ -2,21 +2,9 @@ import { TableGenerics, Row, RowModel, TableInstance } from '../types'
|
|
|
2
2
|
|
|
3
3
|
export function filterRows<TGenerics extends TableGenerics>(
|
|
4
4
|
rows: Row<TGenerics>[],
|
|
5
|
-
|
|
5
|
+
filterRowImpl: (row: Row<TGenerics>) => any,
|
|
6
6
|
instance: TableInstance<TGenerics>
|
|
7
7
|
) {
|
|
8
|
-
const filterRowImpl = (rowsToFilter: Row<TGenerics>[]) => {
|
|
9
|
-
// Horizontally filter rows through each column
|
|
10
|
-
return rowsToFilter.filter(row => {
|
|
11
|
-
for (let i = 0; i < columnIds.length; i++) {
|
|
12
|
-
if (row.columnFilterMap[columnIds[i]] === false) {
|
|
13
|
-
return false
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return true
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
8
|
if (instance.options.filterFromLeafRows) {
|
|
21
9
|
return filterRowModelFromLeafs(rows, filterRowImpl, instance)
|
|
22
10
|
}
|
|
@@ -26,51 +14,40 @@ export function filterRows<TGenerics extends TableGenerics>(
|
|
|
26
14
|
|
|
27
15
|
export function filterRowModelFromLeafs<TGenerics extends TableGenerics>(
|
|
28
16
|
rowsToFilter: Row<TGenerics>[],
|
|
29
|
-
|
|
30
|
-
rowsToFilter: Row<TGenerics>[],
|
|
31
|
-
depth: number
|
|
32
|
-
) => Row<TGenerics>[],
|
|
17
|
+
filterRow: (row: Row<TGenerics>) => Row<TGenerics>[],
|
|
33
18
|
instance: TableInstance<TGenerics>
|
|
34
19
|
): RowModel<TGenerics> {
|
|
35
20
|
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
36
21
|
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
37
22
|
|
|
23
|
+
let row
|
|
24
|
+
let newRow
|
|
25
|
+
|
|
38
26
|
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
39
|
-
|
|
27
|
+
const rows: Row<TGenerics>[] = []
|
|
40
28
|
|
|
41
29
|
// Filter from children up first
|
|
42
30
|
for (let i = 0; i < rowsToFilter.length; i++) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
31
|
+
row = rowsToFilter[i]!
|
|
32
|
+
|
|
33
|
+
if (row.subRows?.length) {
|
|
34
|
+
newRow = instance.createRow(row.id, row.original, row.index, row.depth)
|
|
35
|
+
newRow.columnFilterMap = row.columnFilterMap
|
|
36
|
+
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
37
|
+
if (!newRow.subRows.length) {
|
|
38
|
+
continue
|
|
39
|
+
}
|
|
40
|
+
row = newRow
|
|
47
41
|
}
|
|
48
42
|
|
|
49
|
-
|
|
50
|
-
row
|
|
51
|
-
row.
|
|
52
|
-
row
|
|
53
|
-
row.depth,
|
|
54
|
-
row.values
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
rowsToFilter[i].subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
58
|
-
|
|
59
|
-
if (!rowsToFilter[i].subRows.length) {
|
|
60
|
-
rowsToFilter.splice(i, 1)
|
|
61
|
-
i--
|
|
43
|
+
if (filterRow(row)) {
|
|
44
|
+
rows.push(row)
|
|
45
|
+
newFilteredRowsById[row.id] = row
|
|
46
|
+
newFilteredRowsById[i] = row
|
|
62
47
|
}
|
|
63
48
|
}
|
|
64
49
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// Apply the filter to any subRows
|
|
68
|
-
rowsToFilter.forEach(row => {
|
|
69
|
-
newFilteredFlatRows.push(row)
|
|
70
|
-
newFilteredRowsById[row.id] = row
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
return rowsToFilter
|
|
50
|
+
return rows
|
|
74
51
|
}
|
|
75
52
|
|
|
76
53
|
return {
|
|
@@ -82,45 +59,47 @@ export function filterRowModelFromLeafs<TGenerics extends TableGenerics>(
|
|
|
82
59
|
|
|
83
60
|
export function filterRowModelFromRoot<TGenerics extends TableGenerics>(
|
|
84
61
|
rowsToFilter: Row<TGenerics>[],
|
|
85
|
-
|
|
86
|
-
rowsToFilter: Row<TGenerics>[],
|
|
87
|
-
depth: number
|
|
88
|
-
) => Row<TGenerics>[],
|
|
62
|
+
filterRow: (row: Row<TGenerics>) => any,
|
|
89
63
|
instance: TableInstance<TGenerics>
|
|
90
64
|
): RowModel<TGenerics> {
|
|
91
65
|
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
92
66
|
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
93
67
|
|
|
68
|
+
let rows
|
|
69
|
+
let row
|
|
70
|
+
let newRow
|
|
71
|
+
|
|
94
72
|
// Filters top level and nested rows
|
|
95
73
|
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
96
74
|
// Filter from parents downward first
|
|
97
|
-
|
|
75
|
+
|
|
76
|
+
rows = []
|
|
98
77
|
|
|
99
78
|
// Apply the filter to any subRows
|
|
100
79
|
for (let i = 0; i < rowsToFilter.length; i++) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
80
|
+
row = rowsToFilter[i]!
|
|
81
|
+
|
|
82
|
+
const pass = filterRow(row)
|
|
83
|
+
|
|
84
|
+
if (pass) {
|
|
85
|
+
if (row.subRows?.length) {
|
|
86
|
+
newRow = instance.createRow(
|
|
87
|
+
row.id,
|
|
88
|
+
row.original,
|
|
89
|
+
row.index,
|
|
90
|
+
row.depth
|
|
91
|
+
)
|
|
92
|
+
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
93
|
+
row = newRow
|
|
94
|
+
}
|
|
105
95
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
continue
|
|
96
|
+
rows.push(row)
|
|
97
|
+
newFilteredFlatRows.push(row)
|
|
98
|
+
newFilteredRowsById[row.id] = row
|
|
110
99
|
}
|
|
111
|
-
|
|
112
|
-
rowsToFilter[i] = instance.createRow(
|
|
113
|
-
row.id,
|
|
114
|
-
row.original,
|
|
115
|
-
row.index,
|
|
116
|
-
row.depth,
|
|
117
|
-
row.values
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
rowsToFilter[i].subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
121
100
|
}
|
|
122
101
|
|
|
123
|
-
return
|
|
102
|
+
return rows
|
|
124
103
|
}
|
|
125
104
|
|
|
126
105
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TableInstance, Row, RowModel, TableGenerics } from '../types'
|
|
2
2
|
import { memo } from '../utils'
|
|
3
3
|
|
|
4
|
-
export function
|
|
4
|
+
export function getCoreRowModel<TGenerics extends TableGenerics>(): (
|
|
5
5
|
instance: TableInstance<TGenerics>
|
|
6
6
|
) => () => RowModel<TGenerics> {
|
|
7
7
|
return instance =>
|
|
@@ -46,13 +46,7 @@ export function getCoreRowModelSync<TGenerics extends TableGenerics>(): (
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// Make the row
|
|
49
|
-
const row = instance.createRow(
|
|
50
|
-
id,
|
|
51
|
-
originalRow,
|
|
52
|
-
rowIndex,
|
|
53
|
-
depth,
|
|
54
|
-
values
|
|
55
|
-
)
|
|
49
|
+
const row = instance.createRow(id, originalRow, rowIndex, depth)
|
|
56
50
|
|
|
57
51
|
// Push instance row into the parentRows array
|
|
58
52
|
parentRows.push(row)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TableInstance, TableGenerics } from '../types'
|
|
2
|
+
import { memo } from '../utils'
|
|
3
|
+
|
|
4
|
+
export function getFacetedMinMaxValues<TGenerics extends TableGenerics>(): (
|
|
5
|
+
instance: TableInstance<TGenerics>,
|
|
6
|
+
columnId: string
|
|
7
|
+
) => () => [number, number] {
|
|
8
|
+
return (instance, columnId) =>
|
|
9
|
+
memo(
|
|
10
|
+
() => [instance.getColumn(columnId).getFacetedRowModel()],
|
|
11
|
+
facetedRowModel => {
|
|
12
|
+
let facetedMinMaxValues: [any, any] = [
|
|
13
|
+
facetedRowModel.flatRows[0]?.getValue(columnId) ?? null,
|
|
14
|
+
facetedRowModel.flatRows[0]?.getValue(columnId) ?? null,
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
|
|
18
|
+
const value = facetedRowModel.flatRows[i]?.getValue(columnId)
|
|
19
|
+
|
|
20
|
+
if (value < facetedMinMaxValues[0]) {
|
|
21
|
+
facetedMinMaxValues[0] = value
|
|
22
|
+
} else if (value > facetedMinMaxValues[1]) {
|
|
23
|
+
facetedMinMaxValues[1] = value
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return facetedMinMaxValues
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
key:
|
|
31
|
+
process.env.NODE_ENV === 'development' &&
|
|
32
|
+
'getFacetedMinMaxValues_' + columnId,
|
|
33
|
+
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
34
|
+
onChange: () => {},
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TableInstance, RowModel, TableGenerics, Row } from '../types'
|
|
2
|
+
import { memo } from '../utils'
|
|
3
|
+
import { filterRows } from './filterRowsUtils'
|
|
4
|
+
|
|
5
|
+
export function getFacetedRowModel<TGenerics extends TableGenerics>(): (
|
|
6
|
+
instance: TableInstance<TGenerics>,
|
|
7
|
+
columnId: string
|
|
8
|
+
) => () => RowModel<TGenerics> {
|
|
9
|
+
return (instance, columnId) =>
|
|
10
|
+
memo(
|
|
11
|
+
() => [
|
|
12
|
+
instance.getPreFilteredRowModel(),
|
|
13
|
+
instance.getState().columnFilters,
|
|
14
|
+
instance.getState().globalFilter,
|
|
15
|
+
instance.getFilteredRowModel(),
|
|
16
|
+
],
|
|
17
|
+
(preRowModel, columnFilters, globalFilter) => {
|
|
18
|
+
if (
|
|
19
|
+
!preRowModel.rows.length ||
|
|
20
|
+
(!columnFilters?.length && !globalFilter)
|
|
21
|
+
) {
|
|
22
|
+
return preRowModel
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const filterableIds = [
|
|
26
|
+
...columnFilters.map(d => d.id).filter(d => d !== columnId),
|
|
27
|
+
globalFilter ? '__global__' : undefined,
|
|
28
|
+
].filter(Boolean) as string[]
|
|
29
|
+
|
|
30
|
+
const filterRowsImpl = (row: Row<TGenerics>) => {
|
|
31
|
+
// Horizontally filter rows through each column
|
|
32
|
+
for (let i = 0; i < filterableIds.length; i++) {
|
|
33
|
+
if (row.columnFilterMap[filterableIds[i]!] === false) {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return filterRows(preRowModel.rows, filterRowsImpl, instance)
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
key:
|
|
44
|
+
process.env.NODE_ENV === 'development' &&
|
|
45
|
+
'getFacetedRowModel_' + columnId,
|
|
46
|
+
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
47
|
+
onChange: () => {},
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
}
|