@tanstack/table-core 8.0.0-beta.3 → 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.
- package/build/cjs/core/cell.js +7 -1
- package/build/cjs/core/cell.js.map +1 -1
- package/build/cjs/core/instance.js.map +1 -1
- package/build/cjs/features/Grouping.js +13 -3
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Sorting.js +27 -9
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/esm/index.js +47 -13
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +312 -312
- package/build/types/core/instance.d.ts +1 -0
- package/build/types/features/Sorting.d.ts +1 -0
- package/build/types/types.d.ts +1 -1
- package/build/umd/index.development.js +47 -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/cell.ts +4 -1
- package/src/core/instance.ts +1 -0
- package/src/features/Grouping.ts +13 -2
- package/src/features/Sorting.ts +27 -12
- package/src/types.ts +1 -1
|
@@ -30,6 +30,7 @@ export declare type CoreOptions<TGenerics extends TableGenerics> = {
|
|
|
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;
|
|
@@ -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;
|
package/build/types/types.d.ts
CHANGED
|
@@ -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;
|
|
@@ -1525,6 +1525,12 @@
|
|
|
1525
1525
|
};
|
|
1526
1526
|
},
|
|
1527
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
|
+
|
|
1528
1534
|
return {
|
|
1529
1535
|
getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
|
|
1530
1536
|
getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
|
|
@@ -1534,15 +1540,19 @@
|
|
|
1534
1540
|
return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
|
|
1535
1541
|
},
|
|
1536
1542
|
renderAggregatedCell: () => {
|
|
1537
|
-
|
|
1543
|
+
{
|
|
1544
|
+
if (!column.columnDef.aggregatedCell) {
|
|
1545
|
+
console.warn('A columnDef.aggregatedCell template is recommended for displaying aggregated values.');
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1538
1548
|
|
|
1539
|
-
const template =
|
|
1549
|
+
const template = column.columnDef.aggregatedCell || column.columnDef.cell;
|
|
1540
1550
|
return template ? instance._render(template, {
|
|
1541
1551
|
instance,
|
|
1542
1552
|
column,
|
|
1543
1553
|
row,
|
|
1544
1554
|
cell,
|
|
1545
|
-
getValue:
|
|
1555
|
+
getValue: getRenderValue
|
|
1546
1556
|
}) : null;
|
|
1547
1557
|
}
|
|
1548
1558
|
};
|
|
@@ -2525,8 +2535,10 @@
|
|
|
2525
2535
|
// })
|
|
2526
2536
|
// return
|
|
2527
2537
|
// }
|
|
2538
|
+
// this needs to be outside of instance.setSorting to be in sync with rerender
|
|
2539
|
+
const nextSortingOrder = column.getNextSortingOrder();
|
|
2528
2540
|
instance.setSorting(old => {
|
|
2529
|
-
var
|
|
2541
|
+
var _instance$options$ena, _instance$options$ena2;
|
|
2530
2542
|
|
|
2531
2543
|
// Find any existing sorting for this column
|
|
2532
2544
|
const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
@@ -2551,30 +2563,29 @@
|
|
|
2551
2563
|
} else {
|
|
2552
2564
|
sortAction = 'replace';
|
|
2553
2565
|
}
|
|
2554
|
-
}
|
|
2566
|
+
} // Handle toggle states that will remove the sorting
|
|
2555
2567
|
|
|
2556
|
-
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
|
|
2557
2568
|
|
|
2558
2569
|
if (sortAction === 'toggle' && ( // Must be toggling
|
|
2559
2570
|
(_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
|
|
2560
2571
|
!hasDescDefined && ( // Must not be setting desc
|
|
2561
|
-
multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) &&
|
|
2562
|
-
|
|
2563
|
-
|
|
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
|
+
) {
|
|
2564
2575
|
sortAction = 'remove';
|
|
2565
2576
|
}
|
|
2566
2577
|
|
|
2567
2578
|
if (sortAction === 'replace') {
|
|
2568
2579
|
newSorting = [{
|
|
2569
2580
|
id: column.id,
|
|
2570
|
-
desc: hasDescDefined ? desc :
|
|
2581
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2571
2582
|
}];
|
|
2572
2583
|
} else if (sortAction === 'add' && old != null && old.length) {
|
|
2573
2584
|
var _instance$options$max;
|
|
2574
2585
|
|
|
2575
2586
|
newSorting = [...old, {
|
|
2576
2587
|
id: column.id,
|
|
2577
|
-
desc: hasDescDefined ? desc :
|
|
2588
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2578
2589
|
}]; // Take latest n columns
|
|
2579
2590
|
|
|
2580
2591
|
newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
|
|
@@ -2583,7 +2594,7 @@
|
|
|
2583
2594
|
newSorting = old.map(d => {
|
|
2584
2595
|
if (d.id === column.id) {
|
|
2585
2596
|
return { ...d,
|
|
2586
|
-
desc: hasDescDefined ? desc :
|
|
2597
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2587
2598
|
};
|
|
2588
2599
|
}
|
|
2589
2600
|
|
|
@@ -2596,6 +2607,23 @@
|
|
|
2596
2607
|
return newSorting;
|
|
2597
2608
|
});
|
|
2598
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
|
+
},
|
|
2599
2627
|
getCanSort: () => {
|
|
2600
2628
|
var _column$columnDef$ena, _instance$options$ena3;
|
|
2601
2629
|
|
|
@@ -3043,6 +3071,12 @@
|
|
|
3043
3071
|
}
|
|
3044
3072
|
|
|
3045
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
|
+
|
|
3046
3080
|
const cell = {
|
|
3047
3081
|
id: row.id + "_" + column.id,
|
|
3048
3082
|
row,
|
|
@@ -3054,7 +3088,7 @@
|
|
|
3054
3088
|
column,
|
|
3055
3089
|
row,
|
|
3056
3090
|
cell: cell,
|
|
3057
|
-
getValue:
|
|
3091
|
+
getValue: getRenderValue
|
|
3058
3092
|
}) : null;
|
|
3059
3093
|
}
|
|
3060
3094
|
};
|