@tanstack/table-core 8.0.0-alpha.78 → 8.0.0-alpha.82
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/createTable.js +1 -0
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +1 -1
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Filters.js +2 -1
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Rows.js +1 -1
- package/build/cjs/features/Rows.js.map +1 -1
- package/build/cjs/features/Sorting.js +1 -1
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/index.js +8 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +1 -1
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getFacetedRowModel.js +1 -1
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
- package/build/cjs/utils/getFilteredRowModel.js +20 -9
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
- package/build/esm/index.js +29 -16
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +327 -309
- package/build/types/createTable.d.ts +4 -1
- package/build/types/features/Filters.d.ts +3 -2
- package/build/types/features/Grouping.d.ts +1 -1
- package/build/types/index.d.ts +3 -0
- package/build/types/types.d.ts +1 -0
- package/build/umd/index.development.js +33 -15
- 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/createTable.ts +7 -3
- package/src/features/ColumnSizing.ts +1 -1
- package/src/features/Filters.ts +11 -3
- package/src/features/Grouping.ts +2 -2
- package/src/features/Rows.ts +5 -1
- package/src/features/Sorting.ts +1 -1
- package/src/index.ts +3 -0
- package/src/types.ts +1 -0
- package/src/utils/filterRowsUtils.ts +1 -1
- package/src/utils/getFacetedRowModel.ts +1 -1
- package/src/utils/getFilteredRowModel.ts +24 -13
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.
|
|
4
|
+
"version": "8.0.0-alpha.82",
|
|
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/createTable.ts
CHANGED
|
@@ -42,10 +42,13 @@ export type Table<TGenerics extends TableGenerics> = {
|
|
|
42
42
|
setColumnMetaType: <TColumnMeta>() => Table<
|
|
43
43
|
Overwrite<TGenerics, { ColumnMeta: TColumnMeta }>
|
|
44
44
|
>
|
|
45
|
+
setFilterMetaType: <TFilterMeta>() => Table<
|
|
46
|
+
Overwrite<TGenerics, { FilterMeta: TFilterMeta }>
|
|
47
|
+
>
|
|
45
48
|
setOptions: <
|
|
46
|
-
TFilterFns extends Record<string, FilterFn<
|
|
47
|
-
TSortingFns extends Record<string, SortingFn<
|
|
48
|
-
TAggregationFns extends Record<string, AggregationFn<
|
|
49
|
+
TFilterFns extends Record<string, FilterFn<TGenerics>>,
|
|
50
|
+
TSortingFns extends Record<string, SortingFn<TGenerics>>,
|
|
51
|
+
TAggregationFns extends Record<string, AggregationFn<TGenerics>>
|
|
49
52
|
>(
|
|
50
53
|
options: CreateTableOptions<
|
|
51
54
|
any,
|
|
@@ -144,6 +147,7 @@ function createTable<TGenerics extends TableGenerics>(
|
|
|
144
147
|
setRowType: () => table as any,
|
|
145
148
|
setTableMetaType: () => table as any,
|
|
146
149
|
setColumnMetaType: () => table as any,
|
|
150
|
+
setFilterMetaType: () => table as any,
|
|
147
151
|
setOptions: newOptions =>
|
|
148
152
|
createTable(_, __, {
|
|
149
153
|
...options,
|
package/src/features/Filters.ts
CHANGED
|
@@ -38,7 +38,13 @@ export type ResolvedColumnFilter<TGenerics extends TableGenerics> = {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export type FilterFn<TGenerics extends TableGenerics> = {
|
|
41
|
-
(
|
|
41
|
+
(
|
|
42
|
+
row: Row<TGenerics>,
|
|
43
|
+
columnId: string,
|
|
44
|
+
filterValue: any,
|
|
45
|
+
addMeta: (meta: TGenerics['FilterMeta']) => void
|
|
46
|
+
): boolean
|
|
47
|
+
|
|
42
48
|
resolveFilterValue?: TransformFilterValueFn<TGenerics>
|
|
43
49
|
autoRemove?: ColumnFilterAutoRemoveTestFn<TGenerics>
|
|
44
50
|
}
|
|
@@ -90,7 +96,8 @@ export type FiltersColumn<TGenerics extends TableGenerics> = {
|
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
export type FiltersRow<TGenerics extends TableGenerics> = {
|
|
93
|
-
|
|
99
|
+
columnFilters: Record<string, boolean>
|
|
100
|
+
columnFiltersMeta: Record<string, TGenerics['FilterMeta']>
|
|
94
101
|
subRowsByFacetId: Record<string, Row<TGenerics>[]>
|
|
95
102
|
}
|
|
96
103
|
|
|
@@ -343,7 +350,8 @@ export const Filters: TableFeature = {
|
|
|
343
350
|
instance: TableInstance<TGenerics>
|
|
344
351
|
): FiltersRow<TGenerics> => {
|
|
345
352
|
return {
|
|
346
|
-
|
|
353
|
+
columnFilters: {},
|
|
354
|
+
columnFiltersMeta: {},
|
|
347
355
|
subRowsByFacetId: {},
|
|
348
356
|
}
|
|
349
357
|
},
|
package/src/features/Grouping.ts
CHANGED
|
@@ -16,8 +16,8 @@ import { isFunction, makeStateUpdater, Overwrite } from '../utils'
|
|
|
16
16
|
export type GroupingState = string[]
|
|
17
17
|
|
|
18
18
|
export type AggregationFn<TGenerics extends TableGenerics> = (
|
|
19
|
-
getLeafValues: () => TGenerics['
|
|
20
|
-
getChildValues: () => TGenerics['
|
|
19
|
+
getLeafValues: () => TGenerics['Value'][],
|
|
20
|
+
getChildValues: () => TGenerics['Value'][]
|
|
21
21
|
) => any
|
|
22
22
|
|
|
23
23
|
export type CustomAggregationFns<TGenerics extends TableGenerics> = Record<
|
package/src/features/Rows.ts
CHANGED
|
@@ -85,14 +85,18 @@ export const Rows = {
|
|
|
85
85
|
if (row.valuesCache.hasOwnProperty(columnId)) {
|
|
86
86
|
return row.valuesCache[columnId]
|
|
87
87
|
}
|
|
88
|
+
|
|
88
89
|
const column = instance.getColumn(columnId)
|
|
90
|
+
|
|
89
91
|
if (!column.accessorFn) {
|
|
90
|
-
|
|
92
|
+
return undefined
|
|
91
93
|
}
|
|
94
|
+
|
|
92
95
|
row.valuesCache[columnId] = column.accessorFn(
|
|
93
96
|
row.original,
|
|
94
97
|
rowIndex
|
|
95
98
|
)
|
|
99
|
+
|
|
96
100
|
return row.valuesCache[columnId]
|
|
97
101
|
},
|
|
98
102
|
subRows: subRows ?? [],
|
package/src/features/Sorting.ts
CHANGED
|
@@ -126,7 +126,7 @@ export const Sorting: TableFeature = {
|
|
|
126
126
|
): SortingColumn<TGenerics> => {
|
|
127
127
|
return {
|
|
128
128
|
getAutoSortingFn: () => {
|
|
129
|
-
const firstRows = instance.getFilteredRowModel().flatRows.slice(
|
|
129
|
+
const firstRows = instance.getFilteredRowModel().flatRows.slice(10)
|
|
130
130
|
|
|
131
131
|
let isString = false
|
|
132
132
|
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,9 @@ export * from './features/RowSelection'
|
|
|
14
14
|
export * from './features/Sorting'
|
|
15
15
|
export * from './features/Visibility'
|
|
16
16
|
export * from './features/Expanding'
|
|
17
|
+
export * from './filterFns'
|
|
18
|
+
export * from './sortingFns'
|
|
19
|
+
export * from './aggregationFns'
|
|
17
20
|
export * from './utils'
|
|
18
21
|
export * from './utils/getCoreRowModel'
|
|
19
22
|
export * from './utils/getFilteredRowModel'
|
package/src/types.ts
CHANGED
|
@@ -32,7 +32,7 @@ export function filterRowModelFromLeafs<TGenerics extends TableGenerics>(
|
|
|
32
32
|
|
|
33
33
|
if (row.subRows?.length) {
|
|
34
34
|
newRow = instance.createRow(row.id, row.original, row.index, row.depth)
|
|
35
|
-
newRow.
|
|
35
|
+
newRow.columnFilters = row.columnFilters
|
|
36
36
|
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
37
37
|
if (!newRow.subRows.length) {
|
|
38
38
|
continue
|
|
@@ -30,7 +30,7 @@ export function getFacetedRowModel<TGenerics extends TableGenerics>(): (
|
|
|
30
30
|
const filterRowsImpl = (row: Row<TGenerics>) => {
|
|
31
31
|
// Horizontally filter rows through each column
|
|
32
32
|
for (let i = 0; i < filterableIds.length; i++) {
|
|
33
|
-
if (row.
|
|
33
|
+
if (row.columnFilters[filterableIds[i]!] === false) {
|
|
34
34
|
return false
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -18,6 +18,10 @@ export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
|
|
|
18
18
|
!rowModel.rows.length ||
|
|
19
19
|
(!columnFilters?.length && !globalFilter)
|
|
20
20
|
) {
|
|
21
|
+
for (let i = 0; i < rowModel.flatRows.length; i++) {
|
|
22
|
+
rowModel.flatRows[i]!.columnFilters = {}
|
|
23
|
+
rowModel.flatRows[i]!.columnFiltersMeta = {}
|
|
24
|
+
}
|
|
21
25
|
return rowModel
|
|
22
26
|
}
|
|
23
27
|
|
|
@@ -86,40 +90,47 @@ export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
|
|
|
86
90
|
for (let j = 0; j < rowModel.flatRows.length; j++) {
|
|
87
91
|
const row = rowModel.flatRows[j]!
|
|
88
92
|
|
|
89
|
-
row.
|
|
93
|
+
row.columnFilters = {}
|
|
90
94
|
|
|
91
95
|
if (resolvedColumnFilters.length) {
|
|
92
96
|
for (let i = 0; i < resolvedColumnFilters.length; i++) {
|
|
93
97
|
currentColumnFilter = resolvedColumnFilters[i]!
|
|
98
|
+
const id = currentColumnFilter.id
|
|
94
99
|
|
|
95
100
|
// Tag the row with the column filter state
|
|
96
|
-
row.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
row.columnFilters[id] = currentColumnFilter.filterFn(
|
|
102
|
+
row,
|
|
103
|
+
id,
|
|
104
|
+
currentColumnFilter.resolvedValue,
|
|
105
|
+
filterMeta => {
|
|
106
|
+
row.columnFiltersMeta[id] = filterMeta
|
|
107
|
+
}
|
|
108
|
+
)
|
|
102
109
|
}
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
if (resolvedGlobalFilters.length) {
|
|
106
113
|
for (let i = 0; i < resolvedGlobalFilters.length; i++) {
|
|
107
114
|
currentGlobalFilter = resolvedGlobalFilters[i]!
|
|
115
|
+
const id = currentGlobalFilter.id
|
|
108
116
|
// Tag the row with the first truthy global filter state
|
|
109
117
|
if (
|
|
110
118
|
currentGlobalFilter.filterFn(
|
|
111
119
|
row,
|
|
112
|
-
|
|
113
|
-
currentGlobalFilter.resolvedValue
|
|
120
|
+
id,
|
|
121
|
+
currentGlobalFilter.resolvedValue,
|
|
122
|
+
filterMeta => {
|
|
123
|
+
row.columnFiltersMeta[id] = filterMeta
|
|
124
|
+
}
|
|
114
125
|
)
|
|
115
126
|
) {
|
|
116
|
-
row.
|
|
127
|
+
row.columnFilters.__global__ = true
|
|
117
128
|
break
|
|
118
129
|
}
|
|
119
130
|
}
|
|
120
131
|
|
|
121
|
-
if (row.
|
|
122
|
-
row.
|
|
132
|
+
if (row.columnFilters.__global__ !== true) {
|
|
133
|
+
row.columnFilters.__global__ = false
|
|
123
134
|
}
|
|
124
135
|
}
|
|
125
136
|
}
|
|
@@ -127,7 +138,7 @@ export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
|
|
|
127
138
|
const filterRowsImpl = (row: Row<TGenerics>) => {
|
|
128
139
|
// Horizontally filter rows through each column
|
|
129
140
|
for (let i = 0; i < filterableIds.length; i++) {
|
|
130
|
-
if (row.
|
|
141
|
+
if (row.columnFilters[filterableIds[i]!] === false) {
|
|
131
142
|
return false
|
|
132
143
|
}
|
|
133
144
|
}
|