@tanstack/react-table 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.
@@ -2672,6 +2672,7 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
2672
2672
  original,
2673
2673
  depth,
2674
2674
  _valuesCache: {},
2675
+ _uniqueValuesCache: {},
2675
2676
  getValue: columnId => {
2676
2677
  if (row._valuesCache.hasOwnProperty(columnId)) {
2677
2678
  return row._valuesCache[columnId];
@@ -2683,6 +2684,21 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
2683
2684
  row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
2684
2685
  return row._valuesCache[columnId];
2685
2686
  },
2687
+ getUniqueValues: columnId => {
2688
+ if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
2689
+ return row._uniqueValuesCache[columnId];
2690
+ }
2691
+ const column = table.getColumn(columnId);
2692
+ if (!column.accessorFn) {
2693
+ return undefined;
2694
+ }
2695
+ if (!column.columnDef.getUniqueValues) {
2696
+ row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
2697
+ return row._uniqueValuesCache[columnId];
2698
+ }
2699
+ row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
2700
+ return row._uniqueValuesCache[columnId];
2701
+ },
2686
2702
  renderValue: columnId => row.getValue(columnId) ?? table.options.renderFallbackValue,
2687
2703
  subRows: subRows ?? [],
2688
2704
  getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
@@ -3023,12 +3039,14 @@ function getFacetedUniqueValues() {
3023
3039
  return (table, columnId) => memo(() => [table.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
3024
3040
  let facetedUniqueValues = new Map();
3025
3041
  for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3026
- var _facetedRowModel$flat;
3027
- const value = (_facetedRowModel$flat = facetedRowModel.flatRows[i]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
3028
- if (facetedUniqueValues.has(value)) {
3029
- facetedUniqueValues.set(value, (facetedUniqueValues.get(value) ?? 0) + 1);
3030
- } else {
3031
- facetedUniqueValues.set(value, 1);
3042
+ const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3043
+ for (let j = 0; j < values.length; j++) {
3044
+ const value = values[j];
3045
+ if (facetedUniqueValues.has(value)) {
3046
+ facetedUniqueValues.set(value, (facetedUniqueValues.get(value) ?? 0) + 1);
3047
+ } else {
3048
+ facetedUniqueValues.set(value, 1);
3049
+ }
3032
3050
  }
3033
3051
  }
3034
3052
  return facetedUniqueValues;
@@ -3042,17 +3060,20 @@ function getFacetedUniqueValues() {
3042
3060
  function getFacetedMinMaxValues() {
3043
3061
  return (table, columnId) => memo(() => [table.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
3044
3062
  var _facetedRowModel$flat;
3045
- const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
3063
+ const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getUniqueValues(columnId);
3046
3064
  if (typeof firstValue === 'undefined') {
3047
3065
  return undefined;
3048
3066
  }
3049
3067
  let facetedMinMaxValues = [firstValue, firstValue];
3050
3068
  for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3051
- const value = facetedRowModel.flatRows[i].getValue(columnId);
3052
- if (value < facetedMinMaxValues[0]) {
3053
- facetedMinMaxValues[0] = value;
3054
- } else if (value > facetedMinMaxValues[1]) {
3055
- facetedMinMaxValues[1] = value;
3069
+ const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3070
+ for (let j = 0; j < values.length; j++) {
3071
+ const value = values[j];
3072
+ if (value < facetedMinMaxValues[0]) {
3073
+ facetedMinMaxValues[0] = value;
3074
+ } else if (value > facetedMinMaxValues[1]) {
3075
+ facetedMinMaxValues[1] = value;
3076
+ }
3056
3077
  }
3057
3078
  }
3058
3079
  return facetedMinMaxValues;