@tanstack/table-core 8.5.17 → 8.5.18

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.
@@ -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
- var _facetedRowModel$flat;
3019
- const value = (_facetedRowModel$flat = facetedRowModel.flatRows[i]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
3020
- if (facetedUniqueValues.has(value)) {
3021
- facetedUniqueValues.set(value, (facetedUniqueValues.get(value) ?? 0) + 1);
3022
- } else {
3023
- facetedUniqueValues.set(value, 1);
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.getValue(columnId);
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 value = facetedRowModel.flatRows[i].getValue(columnId);
3044
- if (value < facetedMinMaxValues[0]) {
3045
- facetedMinMaxValues[0] = value;
3046
- } else if (value > facetedMinMaxValues[1]) {
3047
- facetedMinMaxValues[1] = value;
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;