@tanstack/table-core 8.7.9 → 8.8.1

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 (48) hide show
  1. package/build/lib/aggregationFns.js.map +1 -1
  2. package/build/lib/columnHelper.js.map +1 -1
  3. package/build/lib/core/cell.js.map +1 -1
  4. package/build/lib/core/column.js.map +1 -1
  5. package/build/lib/core/headers.js.map +1 -1
  6. package/build/lib/core/row.d.ts +4 -1
  7. package/build/lib/core/row.js +14 -1
  8. package/build/lib/core/row.js.map +1 -1
  9. package/build/lib/core/table.js.map +1 -1
  10. package/build/lib/features/ColumnSizing.js.map +1 -1
  11. package/build/lib/features/Expanding.js.map +1 -1
  12. package/build/lib/features/Filters.js.map +1 -1
  13. package/build/lib/features/Grouping.js.map +1 -1
  14. package/build/lib/features/Ordering.js.map +1 -1
  15. package/build/lib/features/Pagination.js.map +1 -1
  16. package/build/lib/features/Pinning.js.map +1 -1
  17. package/build/lib/features/RowSelection.js.map +1 -1
  18. package/build/lib/features/Sorting.js.map +1 -1
  19. package/build/lib/features/Visibility.js.map +1 -1
  20. package/build/lib/filterFns.js.map +1 -1
  21. package/build/lib/index.esm.js +21 -8
  22. package/build/lib/index.esm.js.map +1 -1
  23. package/build/lib/index.mjs +21 -8
  24. package/build/lib/index.mjs.map +1 -1
  25. package/build/lib/sortingFns.js.map +1 -1
  26. package/build/lib/utils/filterRowsUtils.js +2 -2
  27. package/build/lib/utils/filterRowsUtils.js.map +1 -1
  28. package/build/lib/utils/getCoreRowModel.js +2 -2
  29. package/build/lib/utils/getCoreRowModel.js.map +1 -1
  30. package/build/lib/utils/getExpandedRowModel.js.map +1 -1
  31. package/build/lib/utils/getFacetedMinMaxValues.js.map +1 -1
  32. package/build/lib/utils/getFacetedRowModel.js.map +1 -1
  33. package/build/lib/utils/getFacetedUniqueValues.js.map +1 -1
  34. package/build/lib/utils/getFilteredRowModel.js.map +1 -1
  35. package/build/lib/utils/getGroupedRowModel.js +3 -3
  36. package/build/lib/utils/getGroupedRowModel.js.map +1 -1
  37. package/build/lib/utils/getPaginationRowModel.js.map +1 -1
  38. package/build/lib/utils/getSortedRowModel.js.map +1 -1
  39. package/build/lib/utils.js.map +1 -1
  40. package/build/umd/index.development.js +21 -8
  41. package/build/umd/index.development.js.map +1 -1
  42. package/build/umd/index.production.js +1 -1
  43. package/build/umd/index.production.js.map +1 -1
  44. package/package.json +1 -1
  45. package/src/core/row.ts +18 -1
  46. package/src/utils/filterRowsUtils.ts +6 -2
  47. package/src/utils/getCoreRowModel.ts +5 -3
  48. package/src/utils/getGroupedRowModel.ts +5 -3
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.7.9",
4
+ "version": "8.8.1",
5
5
  "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/tanstack/table#readme",
package/src/core/row.ts CHANGED
@@ -7,6 +7,7 @@ export interface CoreRow<TData extends RowData> {
7
7
  index: number
8
8
  original: TData
9
9
  depth: number
10
+ parentId?: string
10
11
  _valuesCache: Record<string, unknown>
11
12
  _uniqueValuesCache: Record<string, unknown>
12
13
  getValue: <TValue>(columnId: string) => TValue
@@ -17,6 +18,8 @@ export interface CoreRow<TData extends RowData> {
17
18
  originalSubRows?: TData[]
18
19
  getAllCells: () => Cell<TData, unknown>[]
19
20
  _getAllCellsByColumnId: () => Record<string, Cell<TData, unknown>>
21
+ getParentRow: () => Row<TData> | undefined
22
+ getParentRows: () => Row<TData>[]
20
23
  }
21
24
 
22
25
  export const createRow = <TData extends RowData>(
@@ -25,13 +28,15 @@ export const createRow = <TData extends RowData>(
25
28
  original: TData,
26
29
  rowIndex: number,
27
30
  depth: number,
28
- subRows?: Row<TData>[]
31
+ subRows?: Row<TData>[],
32
+ parentId?: string
29
33
  ): Row<TData> => {
30
34
  let row: CoreRow<TData> = {
31
35
  id,
32
36
  index: rowIndex,
33
37
  original,
34
38
  depth,
39
+ parentId,
35
40
  _valuesCache: {},
36
41
  _uniqueValuesCache: {},
37
42
  getValue: columnId => {
@@ -79,6 +84,18 @@ export const createRow = <TData extends RowData>(
79
84
  row.getValue(columnId) ?? table.options.renderFallbackValue,
80
85
  subRows: subRows ?? [],
81
86
  getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
87
+ getParentRow: () => (row.parentId ? table.getRow(row.parentId) : undefined),
88
+ getParentRows: () => {
89
+ let parentRows: Row<TData>[] = []
90
+ let currentRow = row
91
+ while (true) {
92
+ const parentRow = currentRow.getParentRow()
93
+ if (!parentRow) break
94
+ parentRows.push(parentRow)
95
+ currentRow = parentRow
96
+ }
97
+ return parentRows.reverse()
98
+ },
82
99
  getAllCells: memo(
83
100
  () => [table.getAllLeafColumns()],
84
101
  leafColumns => {
@@ -34,7 +34,9 @@ export function filterRowModelFromLeafs<TData extends RowData>(
34
34
  row.id,
35
35
  row.original,
36
36
  row.index,
37
- row.depth
37
+ row.depth,
38
+ undefined,
39
+ row.parentId
38
40
  )
39
41
  newRow.columnFilters = row.columnFilters
40
42
 
@@ -103,7 +105,9 @@ export function filterRowModelFromRoot<TData extends RowData>(
103
105
  row.id,
104
106
  row.original,
105
107
  row.index,
106
- row.depth
108
+ row.depth,
109
+ undefined,
110
+ row.parentId
107
111
  )
108
112
  newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
109
113
  row = newRow
@@ -24,7 +24,7 @@ export function getCoreRowModel<TData extends RowData>(): (
24
24
  const accessRows = (
25
25
  originalRows: TData[],
26
26
  depth = 0,
27
- parent?: Row<TData>
27
+ parentRow?: Row<TData>
28
28
  ): Row<TData>[] => {
29
29
  const rows = [] as Row<TData>[]
30
30
 
@@ -39,10 +39,12 @@ export function getCoreRowModel<TData extends RowData>(): (
39
39
  // Make the row
40
40
  const row = createRow(
41
41
  table,
42
- table._getRowId(originalRows[i]!, i, parent),
42
+ table._getRowId(originalRows[i]!, i, parentRow),
43
43
  originalRows[i]!,
44
44
  i,
45
- depth
45
+ depth,
46
+ undefined,
47
+ parentRow?.id
46
48
  )
47
49
 
48
50
  // Keep track of every row in a flat array
@@ -41,7 +41,7 @@ export function getGroupedRowModel<TData extends RowData>(): (
41
41
  groupedRowsById[row.id] = row
42
42
 
43
43
  if (row.subRows) {
44
- row.subRows = groupUpRecursively(row.subRows, depth + 1)
44
+ row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id)
45
45
  }
46
46
 
47
47
  return row
@@ -72,7 +72,9 @@ export function getGroupedRowModel<TData extends RowData>(): (
72
72
  id,
73
73
  leafRows[0]!.original,
74
74
  index,
75
- depth
75
+ depth,
76
+ undefined,
77
+ parentId
76
78
  )
77
79
 
78
80
  Object.assign(row, {
@@ -134,7 +136,7 @@ export function getGroupedRowModel<TData extends RowData>(): (
134
136
  return aggregatedGroupedRows
135
137
  }
136
138
 
137
- const groupedRows = groupUpRecursively(rowModel.rows, 0, '')
139
+ const groupedRows = groupUpRecursively(rowModel.rows, 0)
138
140
 
139
141
  groupedRows.forEach(subRow => {
140
142
  groupedFlatRows.push(subRow)