@tanstack/react-table 8.0.0-beta.1 → 8.0.0-beta.4

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.
@@ -1106,7 +1106,6 @@ const Filters = {
1106
1106
  },
1107
1107
  createColumn: (column, instance) => {
1108
1108
  return {
1109
- filterFn: column.filterFn,
1110
1109
  getAutoFilterFn: () => {
1111
1110
  const firstRow = instance.getCoreRowModel().flatRows[0];
1112
1111
  const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
@@ -1137,7 +1136,7 @@ const Filters = {
1137
1136
  var _ref;
1138
1137
 
1139
1138
  const userFilterFns = instance.options.filterFns;
1140
- return isFunction(column.filterFn) ? column.filterFn : column.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.filterFn]) != null ? _ref : filterFns[column.filterFn];
1139
+ return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.columnDef.filterFn]) != null ? _ref : filterFns[column.columnDef.filterFn];
1141
1140
  },
1142
1141
  getCanFilter: () => {
1143
1142
  var _column$columnDef$ena, _instance$options$ena, _instance$options$ena2;
@@ -1426,6 +1425,11 @@ const aggregationFns = {
1426
1425
  const Grouping = {
1427
1426
  getDefaultColumnDef: () => {
1428
1427
  return {
1428
+ aggregatedCell: props => {
1429
+ var _props$getValue$toStr, _props$getValue;
1430
+
1431
+ return (_props$getValue$toStr = (_props$getValue = props.getValue()) == null ? void 0 : _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _props$getValue$toStr : null;
1432
+ },
1429
1433
  aggregationFn: 'auto'
1430
1434
  };
1431
1435
  },
@@ -1486,8 +1490,6 @@ const Grouping = {
1486
1490
  if (Object.prototype.toString.call(value) === '[object Date]') {
1487
1491
  return aggregationFns.extent;
1488
1492
  }
1489
-
1490
- return aggregationFns.count;
1491
1493
  },
1492
1494
  getAggregationFn: () => {
1493
1495
  var _ref4;
@@ -1498,7 +1500,7 @@ const Grouping = {
1498
1500
  throw new Error();
1499
1501
  }
1500
1502
 
1501
- return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1503
+ return isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.columnDef.aggregationFn]) != null ? _ref4 : aggregationFns[column.columnDef.aggregationFn];
1502
1504
  }
1503
1505
  };
1504
1506
  },
@@ -1531,6 +1533,12 @@ const Grouping = {
1531
1533
  };
1532
1534
  },
1533
1535
  createCell: (cell, column, row, instance) => {
1536
+ const getRenderValue = () => {
1537
+ var _cell$getValue;
1538
+
1539
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
1540
+ };
1541
+
1534
1542
  return {
1535
1543
  getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
1536
1544
  getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
@@ -1540,15 +1548,19 @@ const Grouping = {
1540
1548
  return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
1541
1549
  },
1542
1550
  renderAggregatedCell: () => {
1543
- var _column$columnDef$agg;
1551
+ if (process.env.NODE_ENV === 'development') {
1552
+ if (!column.columnDef.aggregatedCell) {
1553
+ console.warn('A columnDef.aggregatedCell template is recommended for displaying aggregated values.');
1554
+ }
1555
+ }
1544
1556
 
1545
- const template = (_column$columnDef$agg = column.columnDef.aggregatedCell) != null ? _column$columnDef$agg : column.columnDef.cell;
1557
+ const template = column.columnDef.aggregatedCell || column.columnDef.cell;
1546
1558
  return template ? instance._render(template, {
1547
1559
  instance,
1548
1560
  column,
1549
1561
  row,
1550
1562
  cell,
1551
- getValue: cell.getValue
1563
+ getValue: getRenderValue
1552
1564
  }) : null;
1553
1565
  }
1554
1566
  };
@@ -2531,8 +2543,10 @@ const Sorting = {
2531
2543
  // })
2532
2544
  // return
2533
2545
  // }
2546
+ // this needs to be outside of instance.setSorting to be in sync with rerender
2547
+ const nextSortingOrder = column.getNextSortingOrder();
2534
2548
  instance.setSorting(old => {
2535
- var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
2549
+ var _instance$options$ena, _instance$options$ena2;
2536
2550
 
2537
2551
  // Find any existing sorting for this column
2538
2552
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
@@ -2557,30 +2571,29 @@ const Sorting = {
2557
2571
  } else {
2558
2572
  sortAction = 'replace';
2559
2573
  }
2560
- }
2574
+ } // Handle toggle states that will remove the sorting
2561
2575
 
2562
- const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc'; // Handle toggle states that will remove the sorting
2563
2576
 
2564
2577
  if (sortAction === 'toggle' && ( // Must be toggling
2565
2578
  (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2566
2579
  !hasDescDefined && ( // Must not be setting desc
2567
- multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2568
- existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2569
- ? !sortDescFirst : sortDescFirst)) {
2580
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && // If multi, don't allow if enableMultiRemove
2581
+ !nextSortingOrder // Finally, detect if it should indeed be removed
2582
+ ) {
2570
2583
  sortAction = 'remove';
2571
2584
  }
2572
2585
 
2573
2586
  if (sortAction === 'replace') {
2574
2587
  newSorting = [{
2575
2588
  id: column.id,
2576
- desc: hasDescDefined ? desc : !!sortDescFirst
2589
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2577
2590
  }];
2578
2591
  } else if (sortAction === 'add' && old != null && old.length) {
2579
2592
  var _instance$options$max;
2580
2593
 
2581
2594
  newSorting = [...old, {
2582
2595
  id: column.id,
2583
- desc: hasDescDefined ? desc : !!sortDescFirst
2596
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2584
2597
  }]; // Take latest n columns
2585
2598
 
2586
2599
  newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
@@ -2589,7 +2602,7 @@ const Sorting = {
2589
2602
  newSorting = old.map(d => {
2590
2603
  if (d.id === column.id) {
2591
2604
  return { ...d,
2592
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2605
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2593
2606
  };
2594
2607
  }
2595
2608
 
@@ -2602,6 +2615,23 @@ const Sorting = {
2602
2615
  return newSorting;
2603
2616
  });
2604
2617
  },
2618
+ getNextSortingOrder: () => {
2619
+ var _ref2, _column$columnDef$sor;
2620
+
2621
+ const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc';
2622
+ const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2623
+ const isSorted = column.getIsSorted();
2624
+
2625
+ if (!isSorted) {
2626
+ return firstSortDirection;
2627
+ }
2628
+
2629
+ if (isSorted === firstSortDirection) {
2630
+ return isSorted === 'desc' ? 'asc' : 'desc';
2631
+ } else {
2632
+ return false;
2633
+ }
2634
+ },
2605
2635
  getCanSort: () => {
2606
2636
  var _column$columnDef$ena, _instance$options$ena3;
2607
2637
 
@@ -2895,9 +2925,9 @@ function createTableInstance(options) {
2895
2925
  header: props => props.header.column.id,
2896
2926
  footer: props => props.header.column.id,
2897
2927
  cell: props => {
2898
- var _props$getValue$toStr, _props$getValue$toStr2, _props$getValue;
2928
+ var _props$getValue$toStr, _props$getValue;
2899
2929
 
2900
- return (_props$getValue$toStr = (_props$getValue$toStr2 = (_props$getValue = props.getValue()).toString) == null ? void 0 : _props$getValue$toStr2.call(_props$getValue)) != null ? _props$getValue$toStr : null;
2930
+ return (_props$getValue$toStr = (_props$getValue = props.getValue()) == null ? void 0 : _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _props$getValue$toStr : null;
2901
2931
  },
2902
2932
  ...instance._features.reduce((obj, feature) => {
2903
2933
  return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
@@ -3051,6 +3081,12 @@ function createTable$1(_, __, options) {
3051
3081
  }
3052
3082
 
3053
3083
  function createCell(instance, row, column, columnId) {
3084
+ const getRenderValue = () => {
3085
+ var _cell$getValue;
3086
+
3087
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
3088
+ };
3089
+
3054
3090
  const cell = {
3055
3091
  id: row.id + "_" + column.id,
3056
3092
  row,
@@ -3062,7 +3098,7 @@ function createCell(instance, row, column, columnId) {
3062
3098
  column,
3063
3099
  row,
3064
3100
  cell: cell,
3065
- getValue: cell.getValue
3101
+ getValue: getRenderValue
3066
3102
  }) : null;
3067
3103
  }
3068
3104
  };
@@ -3668,11 +3704,6 @@ function getGroupedRowModel() {
3668
3704
  if (aggregateFn) {
3669
3705
  row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
3670
3706
  return row._groupingValuesCache[columnId];
3671
- } else if (column.aggregationFn) {
3672
- console.info({
3673
- column
3674
- });
3675
- throw new Error(process.env.NODE_ENV !== 'production' ? "Table: Invalid column.aggregateType option for column listed above" : '');
3676
3707
  }
3677
3708
  }
3678
3709
  });
@@ -3851,6 +3882,7 @@ function useTableInstance(table, options) {
3851
3882
  onStateChange: () => {},
3852
3883
  // noop
3853
3884
  render,
3885
+ renderFallbackValue: null,
3854
3886
  ...options
3855
3887
  }; // Create a new table instance and store it in state
3856
3888