@tanstack/table-core 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.
Files changed (39) hide show
  1. package/build/cjs/core/cell.js +7 -1
  2. package/build/cjs/core/cell.js.map +1 -1
  3. package/build/cjs/core/instance.js +2 -2
  4. package/build/cjs/core/instance.js.map +1 -1
  5. package/build/cjs/features/Expanding.js.map +1 -1
  6. package/build/cjs/features/Filters.js +1 -2
  7. package/build/cjs/features/Filters.js.map +1 -1
  8. package/build/cjs/features/Grouping.js +19 -6
  9. package/build/cjs/features/Grouping.js.map +1 -1
  10. package/build/cjs/features/Pagination.js.map +1 -1
  11. package/build/cjs/features/Sorting.js +27 -9
  12. package/build/cjs/features/Sorting.js.map +1 -1
  13. package/build/cjs/utils/getGroupedRowModel.js +0 -5
  14. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  15. package/build/esm/index.js +56 -25
  16. package/build/esm/index.js.map +1 -1
  17. package/build/stats-html.html +1 -1
  18. package/build/stats-react.json +318 -318
  19. package/build/types/core/instance.d.ts +2 -1
  20. package/build/types/features/Expanding.d.ts +1 -1
  21. package/build/types/features/Filters.d.ts +1 -4
  22. package/build/types/features/Grouping.d.ts +1 -4
  23. package/build/types/features/Pagination.d.ts +1 -1
  24. package/build/types/features/Sorting.d.ts +2 -1
  25. package/build/types/types.d.ts +1 -1
  26. package/build/umd/index.development.js +56 -25
  27. package/build/umd/index.development.js.map +1 -1
  28. package/build/umd/index.production.js +1 -1
  29. package/build/umd/index.production.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/core/cell.ts +4 -1
  32. package/src/core/instance.ts +3 -4
  33. package/src/features/Expanding.ts +1 -3
  34. package/src/features/Filters.ts +6 -10
  35. package/src/features/Grouping.ts +20 -13
  36. package/src/features/Pagination.ts +1 -3
  37. package/src/features/Sorting.ts +28 -15
  38. package/src/types.ts +1 -1
  39. package/src/utils/getGroupedRowModel.ts +0 -7
@@ -25,11 +25,12 @@ export declare type CoreOptions<TGenerics extends TableGenerics> = {
25
25
  autoResetAll?: boolean;
26
26
  mergeOptions?: <T>(defaultOptions: T, options: Partial<T>) => T;
27
27
  meta?: TGenerics['TableMeta'];
28
- getCoreRowModel: (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics>;
28
+ getCoreRowModel: (instance: TableInstance<any>) => () => RowModel<any>;
29
29
  getSubRows?: (originalRow: TGenerics['Row'], index: number) => undefined | TGenerics['Row'][];
30
30
  getRowId?: (originalRow: TGenerics['Row'], index: number, parent?: Row<TGenerics>) => string;
31
31
  columns: ColumnDef<TGenerics>[];
32
32
  defaultColumn?: Partial<ColumnDef<TGenerics>>;
33
+ renderFallbackValue: any;
33
34
  };
34
35
  export declare type CoreInstance<TGenerics extends TableGenerics> = {
35
36
  initialState: TableState;
@@ -17,7 +17,7 @@ export declare type ExpandedOptions<TGenerics extends TableGenerics> = {
17
17
  onExpandedChange?: OnChangeFn<ExpandedState>;
18
18
  autoResetExpanded?: boolean;
19
19
  enableExpanding?: boolean;
20
- getExpandedRowModel?: (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics>;
20
+ getExpandedRowModel?: (instance: TableInstance<any>) => () => RowModel<any>;
21
21
  getIsRowExpanded?: (row: Row<TGenerics>) => boolean;
22
22
  getRowCanExpand?: (row: Row<TGenerics>) => boolean;
23
23
  paginateExpandedRows?: boolean;
@@ -34,9 +34,6 @@ export declare type FiltersColumnDef<TGenerics extends TableGenerics> = {
34
34
  enableGlobalFilter?: boolean;
35
35
  };
36
36
  export declare type FiltersColumn<TGenerics extends TableGenerics> = {
37
- filterFn: FilterFnOption<Overwrite<TGenerics, {
38
- Value: any;
39
- }>>;
40
37
  getAutoFilterFn: () => FilterFn<TGenerics> | undefined;
41
38
  getFilterFn: () => FilterFn<TGenerics> | undefined;
42
39
  setFilterValue: (updater: Updater<any>) => void;
@@ -61,7 +58,7 @@ export declare type FiltersOptions<TGenerics extends TableGenerics> = {
61
58
  manualFiltering?: boolean;
62
59
  filterFromLeafRows?: boolean;
63
60
  filterFns?: TGenerics['FilterFns'];
64
- getFilteredRowModel?: (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics>;
61
+ getFilteredRowModel?: (instance: TableInstance<any>) => () => RowModel<any>;
65
62
  onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>;
66
63
  enableColumnFilters?: boolean;
67
64
  globalFilterFn?: FilterFnOption<TGenerics>;
@@ -24,9 +24,6 @@ export declare type GroupingColumnDef<TGenerics extends TableGenerics> = {
24
24
  enableGrouping?: boolean;
25
25
  };
26
26
  export declare type GroupingColumn<TGenerics extends TableGenerics> = {
27
- aggregationFn?: AggregationFnOption<Overwrite<TGenerics, {
28
- Value: any;
29
- }>>;
30
27
  getCanGroup: () => boolean;
31
28
  getIsGrouped: () => boolean;
32
29
  getGroupedIndex: () => number;
@@ -56,7 +53,7 @@ export declare type GroupingOptions<TGenerics extends TableGenerics> = {
56
53
  aggregationFns?: TGenerics['AggregationFns'];
57
54
  onGroupingChange?: OnChangeFn<GroupingState>;
58
55
  enableGrouping?: boolean;
59
- getGroupedRowModel?: (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics>;
56
+ getGroupedRowModel?: (instance: TableInstance<any>) => () => RowModel<any>;
60
57
  groupedColumnMode?: false | 'reorder' | 'remove';
61
58
  };
62
59
  export declare type GroupingColumnMode = false | 'reorder' | 'remove';
@@ -15,7 +15,7 @@ export declare type PaginationOptions<TGenerics extends TableGenerics> = {
15
15
  manualPagination?: boolean;
16
16
  onPaginationChange?: OnChangeFn<PaginationState>;
17
17
  autoResetPageIndex?: boolean;
18
- getPaginationRowModel?: (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics>;
18
+ getPaginationRowModel?: (instance: TableInstance<any>) => () => RowModel<any>;
19
19
  };
20
20
  export declare type PaginationDefaultOptions = {
21
21
  onPaginationChange: OnChangeFn<PaginationState>;
@@ -31,6 +31,7 @@ export declare type SortingColumn<TGenerics extends TableGenerics> = {
31
31
  getAutoSortingFn: () => SortingFn<TGenerics>;
32
32
  getAutoSortDir: () => SortDirection;
33
33
  getSortingFn: () => SortingFn<TGenerics>;
34
+ getNextSortingOrder: () => SortDirection | false;
34
35
  getCanSort: () => boolean;
35
36
  getCanMultiSort: () => boolean;
36
37
  getSortIndex: () => number;
@@ -48,7 +49,7 @@ export declare type SortingOptions<TGenerics extends TableGenerics> = {
48
49
  enableMultiRemove?: boolean;
49
50
  enableMultiSort?: boolean;
50
51
  sortDescFirst?: boolean;
51
- getSortedRowModel?: (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics>;
52
+ getSortedRowModel?: (instance: TableInstance<any>) => () => RowModel<any>;
52
53
  maxMultiSortColCount?: number;
53
54
  isMultiSortEvent?: (e: unknown) => boolean;
54
55
  };
@@ -31,7 +31,7 @@ export declare type TableGenerics = {
31
31
  export declare type AnyRender = (Comp: any, props: any) => any;
32
32
  export declare type TableInstance<TGenerics extends TableGenerics> = CoreInstance<TGenerics> & HeadersInstance<TGenerics> & VisibilityInstance<TGenerics> & ColumnOrderInstance<TGenerics> & ColumnPinningInstance<TGenerics> & FiltersInstance<TGenerics> & SortingInstance<TGenerics> & GroupingInstance<TGenerics> & ColumnSizingInstance<TGenerics> & ExpandedInstance<TGenerics> & PaginationInstance<TGenerics> & RowSelectionInstance<TGenerics>;
33
33
  export declare type TableOptionsResolved<TGenerics extends TableGenerics> = CoreOptions<TGenerics> & VisibilityOptions & ColumnOrderOptions & ColumnPinningOptions & FiltersOptions<TGenerics> & SortingOptions<TGenerics> & GroupingOptions<TGenerics> & ExpandedOptions<TGenerics> & ColumnSizingOptions & PaginationOptions<TGenerics> & RowSelectionOptions<TGenerics>;
34
- export declare type TableOptions<TGenerics extends TableGenerics> = Omit<PartialKeys<TableOptionsResolved<TGenerics>, 'state' | 'onStateChange'>, 'render'>;
34
+ export declare type TableOptions<TGenerics extends TableGenerics> = Omit<PartialKeys<TableOptionsResolved<TGenerics>, 'state' | 'onStateChange'>, 'render' | 'renderFallbackValue'>;
35
35
  export declare type TableState = CoreTableState & VisibilityTableState & ColumnOrderTableState & ColumnPinningTableState & FiltersTableState & SortingTableState & ExpandedTableState & GroupingTableState & ColumnSizingTableState & PaginationTableState & RowSelectionTableState;
36
36
  export declare type InitialTableState = Partial<CoreTableState & VisibilityTableState & ColumnOrderTableState & ColumnPinningTableState & FiltersTableState & SortingTableState & ExpandedTableState & GroupingTableState & ColumnSizingTableState & PaginationInitialTableState & RowSelectionTableState>;
37
37
  export declare type Row<TGenerics extends TableGenerics> = CoreRow<TGenerics> & VisibilityRow<TGenerics> & ColumnPinningRow<TGenerics> & FiltersRow<TGenerics> & GroupingRow & RowSelectionRow & ExpandedRow;
@@ -1098,7 +1098,6 @@
1098
1098
  },
1099
1099
  createColumn: (column, instance) => {
1100
1100
  return {
1101
- filterFn: column.filterFn,
1102
1101
  getAutoFilterFn: () => {
1103
1102
  const firstRow = instance.getCoreRowModel().flatRows[0];
1104
1103
  const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
@@ -1129,7 +1128,7 @@
1129
1128
  var _ref;
1130
1129
 
1131
1130
  const userFilterFns = instance.options.filterFns;
1132
- return isFunction(column.filterFn) ? column.filterFn : column.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.filterFn]) != null ? _ref : filterFns[column.filterFn];
1131
+ 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];
1133
1132
  },
1134
1133
  getCanFilter: () => {
1135
1134
  var _column$columnDef$ena, _instance$options$ena, _instance$options$ena2;
@@ -1418,6 +1417,11 @@
1418
1417
  const Grouping = {
1419
1418
  getDefaultColumnDef: () => {
1420
1419
  return {
1420
+ aggregatedCell: props => {
1421
+ var _props$getValue$toStr, _props$getValue;
1422
+
1423
+ 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;
1424
+ },
1421
1425
  aggregationFn: 'auto'
1422
1426
  };
1423
1427
  },
@@ -1478,8 +1482,6 @@
1478
1482
  if (Object.prototype.toString.call(value) === '[object Date]') {
1479
1483
  return aggregationFns.extent;
1480
1484
  }
1481
-
1482
- return aggregationFns.count;
1483
1485
  },
1484
1486
  getAggregationFn: () => {
1485
1487
  var _ref4;
@@ -1490,7 +1492,7 @@
1490
1492
  throw new Error();
1491
1493
  }
1492
1494
 
1493
- return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1495
+ 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];
1494
1496
  }
1495
1497
  };
1496
1498
  },
@@ -1523,6 +1525,12 @@
1523
1525
  };
1524
1526
  },
1525
1527
  createCell: (cell, column, row, instance) => {
1528
+ const getRenderValue = () => {
1529
+ var _cell$getValue;
1530
+
1531
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
1532
+ };
1533
+
1526
1534
  return {
1527
1535
  getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
1528
1536
  getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
@@ -1532,15 +1540,19 @@
1532
1540
  return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
1533
1541
  },
1534
1542
  renderAggregatedCell: () => {
1535
- var _column$columnDef$agg;
1543
+ {
1544
+ if (!column.columnDef.aggregatedCell) {
1545
+ console.warn('A columnDef.aggregatedCell template is recommended for displaying aggregated values.');
1546
+ }
1547
+ }
1536
1548
 
1537
- const template = (_column$columnDef$agg = column.columnDef.aggregatedCell) != null ? _column$columnDef$agg : column.columnDef.cell;
1549
+ const template = column.columnDef.aggregatedCell || column.columnDef.cell;
1538
1550
  return template ? instance._render(template, {
1539
1551
  instance,
1540
1552
  column,
1541
1553
  row,
1542
1554
  cell,
1543
- getValue: cell.getValue
1555
+ getValue: getRenderValue
1544
1556
  }) : null;
1545
1557
  }
1546
1558
  };
@@ -2523,8 +2535,10 @@
2523
2535
  // })
2524
2536
  // return
2525
2537
  // }
2538
+ // this needs to be outside of instance.setSorting to be in sync with rerender
2539
+ const nextSortingOrder = column.getNextSortingOrder();
2526
2540
  instance.setSorting(old => {
2527
- var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
2541
+ var _instance$options$ena, _instance$options$ena2;
2528
2542
 
2529
2543
  // Find any existing sorting for this column
2530
2544
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
@@ -2549,30 +2563,29 @@
2549
2563
  } else {
2550
2564
  sortAction = 'replace';
2551
2565
  }
2552
- }
2566
+ } // Handle toggle states that will remove the sorting
2553
2567
 
2554
- 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
2555
2568
 
2556
2569
  if (sortAction === 'toggle' && ( // Must be toggling
2557
2570
  (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2558
2571
  !hasDescDefined && ( // Must not be setting desc
2559
- multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2560
- existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2561
- ? !sortDescFirst : sortDescFirst)) {
2572
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && // If multi, don't allow if enableMultiRemove
2573
+ !nextSortingOrder // Finally, detect if it should indeed be removed
2574
+ ) {
2562
2575
  sortAction = 'remove';
2563
2576
  }
2564
2577
 
2565
2578
  if (sortAction === 'replace') {
2566
2579
  newSorting = [{
2567
2580
  id: column.id,
2568
- desc: hasDescDefined ? desc : !!sortDescFirst
2581
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2569
2582
  }];
2570
2583
  } else if (sortAction === 'add' && old != null && old.length) {
2571
2584
  var _instance$options$max;
2572
2585
 
2573
2586
  newSorting = [...old, {
2574
2587
  id: column.id,
2575
- desc: hasDescDefined ? desc : !!sortDescFirst
2588
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2576
2589
  }]; // Take latest n columns
2577
2590
 
2578
2591
  newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
@@ -2581,7 +2594,7 @@
2581
2594
  newSorting = old.map(d => {
2582
2595
  if (d.id === column.id) {
2583
2596
  return { ...d,
2584
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2597
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2585
2598
  };
2586
2599
  }
2587
2600
 
@@ -2594,6 +2607,23 @@
2594
2607
  return newSorting;
2595
2608
  });
2596
2609
  },
2610
+ getNextSortingOrder: () => {
2611
+ var _ref2, _column$columnDef$sor;
2612
+
2613
+ const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc';
2614
+ const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2615
+ const isSorted = column.getIsSorted();
2616
+
2617
+ if (!isSorted) {
2618
+ return firstSortDirection;
2619
+ }
2620
+
2621
+ if (isSorted === firstSortDirection) {
2622
+ return isSorted === 'desc' ? 'asc' : 'desc';
2623
+ } else {
2624
+ return false;
2625
+ }
2626
+ },
2597
2627
  getCanSort: () => {
2598
2628
  var _column$columnDef$ena, _instance$options$ena3;
2599
2629
 
@@ -2885,9 +2915,9 @@
2885
2915
  header: props => props.header.column.id,
2886
2916
  footer: props => props.header.column.id,
2887
2917
  cell: props => {
2888
- var _props$getValue$toStr, _props$getValue$toStr2, _props$getValue;
2918
+ var _props$getValue$toStr, _props$getValue;
2889
2919
 
2890
- 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;
2920
+ 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;
2891
2921
  },
2892
2922
  ...instance._features.reduce((obj, feature) => {
2893
2923
  return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
@@ -3041,6 +3071,12 @@
3041
3071
  }
3042
3072
 
3043
3073
  function createCell(instance, row, column, columnId) {
3074
+ const getRenderValue = () => {
3075
+ var _cell$getValue;
3076
+
3077
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
3078
+ };
3079
+
3044
3080
  const cell = {
3045
3081
  id: row.id + "_" + column.id,
3046
3082
  row,
@@ -3052,7 +3088,7 @@
3052
3088
  column,
3053
3089
  row,
3054
3090
  cell: cell,
3055
- getValue: cell.getValue
3091
+ getValue: getRenderValue
3056
3092
  }) : null;
3057
3093
  }
3058
3094
  };
@@ -3658,11 +3694,6 @@
3658
3694
  if (aggregateFn) {
3659
3695
  row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
3660
3696
  return row._groupingValuesCache[columnId];
3661
- } else if (column.aggregationFn) {
3662
- console.info({
3663
- column
3664
- });
3665
- throw new Error("Table: Invalid column.aggregateType option for column listed above" );
3666
3697
  }
3667
3698
  }
3668
3699
  });