@tanstack/table-core 8.5.17 → 8.5.19
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/row.js +16 -0
- package/build/cjs/core/row.js.map +1 -1
- package/build/cjs/utils/getFacetedMinMaxValues.js +9 -6
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -1
- package/build/cjs/utils/getFacetedUniqueValues.js +8 -6
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +1 -1
- package/build/cjs/utils/getSortedRowModel.js.map +1 -1
- package/build/esm/index.js +34 -13
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +318 -318
- package/build/types/index.d.ts +3 -0
- package/build/umd/index.development.js +34 -13
- 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/row.ts +26 -0
- package/src/types.ts +1 -0
- package/src/utils/getFacetedMinMaxValues.ts +12 -6
- package/src/utils/getFacetedUniqueValues.ts +13 -8
- package/src/utils/getSortedRowModel.ts +1 -1
package/build/types/index.d.ts
CHANGED
|
@@ -577,7 +577,9 @@ declare type CoreRow<TData extends RowData> = {
|
|
|
577
577
|
original: TData;
|
|
578
578
|
depth: number;
|
|
579
579
|
_valuesCache: Record<string, unknown>;
|
|
580
|
+
_uniqueValuesCache: Record<string, unknown>;
|
|
580
581
|
getValue: <TValue>(columnId: string) => TValue;
|
|
582
|
+
getUniqueValues: <TValue>(columnId: string) => TValue[];
|
|
581
583
|
renderValue: <TValue>(columnId: string) => TValue;
|
|
582
584
|
subRows: Row<TData>[];
|
|
583
585
|
getLeafRows: () => Row<TData>[];
|
|
@@ -657,6 +659,7 @@ declare type IdIdentifier<TData extends RowData, TValue> = {
|
|
|
657
659
|
};
|
|
658
660
|
declare type ColumnIdentifiers<TData extends RowData, TValue> = IdIdentifier<TData, TValue> | StringHeaderIdentifier;
|
|
659
661
|
declare type ColumnDefBase<TData extends RowData, TValue = unknown> = {
|
|
662
|
+
getUniqueValues?: AccessorFn<TData, unknown[]>;
|
|
660
663
|
footer?: ColumnDefTemplate<HeaderContext<TData, TValue>>;
|
|
661
664
|
cell?: ColumnDefTemplate<CellContext<TData, TValue>>;
|
|
662
665
|
meta?: ColumnMeta<TData, TValue>;
|
|
@@ -2664,6 +2664,7 @@
|
|
|
2664
2664
|
original,
|
|
2665
2665
|
depth,
|
|
2666
2666
|
_valuesCache: {},
|
|
2667
|
+
_uniqueValuesCache: {},
|
|
2667
2668
|
getValue: columnId => {
|
|
2668
2669
|
if (row._valuesCache.hasOwnProperty(columnId)) {
|
|
2669
2670
|
return row._valuesCache[columnId];
|
|
@@ -2675,6 +2676,21 @@
|
|
|
2675
2676
|
row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
|
|
2676
2677
|
return row._valuesCache[columnId];
|
|
2677
2678
|
},
|
|
2679
|
+
getUniqueValues: columnId => {
|
|
2680
|
+
if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
|
|
2681
|
+
return row._uniqueValuesCache[columnId];
|
|
2682
|
+
}
|
|
2683
|
+
const column = table.getColumn(columnId);
|
|
2684
|
+
if (!column.accessorFn) {
|
|
2685
|
+
return undefined;
|
|
2686
|
+
}
|
|
2687
|
+
if (!column.columnDef.getUniqueValues) {
|
|
2688
|
+
row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
|
|
2689
|
+
return row._uniqueValuesCache[columnId];
|
|
2690
|
+
}
|
|
2691
|
+
row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
|
|
2692
|
+
return row._uniqueValuesCache[columnId];
|
|
2693
|
+
},
|
|
2678
2694
|
renderValue: columnId => row.getValue(columnId) ?? table.options.renderFallbackValue,
|
|
2679
2695
|
subRows: subRows ?? [],
|
|
2680
2696
|
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
@@ -3015,12 +3031,14 @@
|
|
|
3015
3031
|
return (table, columnId) => memo(() => [table.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
|
|
3016
3032
|
let facetedUniqueValues = new Map();
|
|
3017
3033
|
for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3034
|
+
const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
|
|
3035
|
+
for (let j = 0; j < values.length; j++) {
|
|
3036
|
+
const value = values[j];
|
|
3037
|
+
if (facetedUniqueValues.has(value)) {
|
|
3038
|
+
facetedUniqueValues.set(value, (facetedUniqueValues.get(value) ?? 0) + 1);
|
|
3039
|
+
} else {
|
|
3040
|
+
facetedUniqueValues.set(value, 1);
|
|
3041
|
+
}
|
|
3024
3042
|
}
|
|
3025
3043
|
}
|
|
3026
3044
|
return facetedUniqueValues;
|
|
@@ -3034,17 +3052,20 @@
|
|
|
3034
3052
|
function getFacetedMinMaxValues() {
|
|
3035
3053
|
return (table, columnId) => memo(() => [table.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
|
|
3036
3054
|
var _facetedRowModel$flat;
|
|
3037
|
-
const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.
|
|
3055
|
+
const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getUniqueValues(columnId);
|
|
3038
3056
|
if (typeof firstValue === 'undefined') {
|
|
3039
3057
|
return undefined;
|
|
3040
3058
|
}
|
|
3041
3059
|
let facetedMinMaxValues = [firstValue, firstValue];
|
|
3042
3060
|
for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
|
|
3043
|
-
const
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3061
|
+
const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
|
|
3062
|
+
for (let j = 0; j < values.length; j++) {
|
|
3063
|
+
const value = values[j];
|
|
3064
|
+
if (value < facetedMinMaxValues[0]) {
|
|
3065
|
+
facetedMinMaxValues[0] = value;
|
|
3066
|
+
} else if (value > facetedMinMaxValues[1]) {
|
|
3067
|
+
facetedMinMaxValues[1] = value;
|
|
3068
|
+
}
|
|
3048
3069
|
}
|
|
3049
3070
|
}
|
|
3050
3071
|
return facetedMinMaxValues;
|
|
@@ -3077,7 +3098,7 @@
|
|
|
3077
3098
|
const sortData = rows => {
|
|
3078
3099
|
// This will also perform a stable sorting using the row index
|
|
3079
3100
|
// if needed.
|
|
3080
|
-
const sortedData = rows
|
|
3101
|
+
const sortedData = [...rows];
|
|
3081
3102
|
sortedData.sort((rowA, rowB) => {
|
|
3082
3103
|
for (let i = 0; i < availableSorting.length; i += 1) {
|
|
3083
3104
|
const sortEntry = availableSorting[i];
|