@tanstack/react-table 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/react-table/src/index.js +1 -0
- package/build/cjs/react-table/src/index.js.map +1 -1
- package/build/cjs/table-core/build/esm/index.js +47 -13
- package/build/cjs/table-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +48 -13
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +19 -19
- package/build/umd/index.development.js +48 -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 +2 -2
- package/src/index.tsx +1 -0
package/build/esm/index.js
CHANGED
|
@@ -1533,6 +1533,12 @@ const Grouping = {
|
|
|
1533
1533
|
};
|
|
1534
1534
|
},
|
|
1535
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
|
+
|
|
1536
1542
|
return {
|
|
1537
1543
|
getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
|
|
1538
1544
|
getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
|
|
@@ -1542,15 +1548,19 @@ const Grouping = {
|
|
|
1542
1548
|
return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
|
|
1543
1549
|
},
|
|
1544
1550
|
renderAggregatedCell: () => {
|
|
1545
|
-
|
|
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
|
+
}
|
|
1546
1556
|
|
|
1547
|
-
const template =
|
|
1557
|
+
const template = column.columnDef.aggregatedCell || column.columnDef.cell;
|
|
1548
1558
|
return template ? instance._render(template, {
|
|
1549
1559
|
instance,
|
|
1550
1560
|
column,
|
|
1551
1561
|
row,
|
|
1552
1562
|
cell,
|
|
1553
|
-
getValue:
|
|
1563
|
+
getValue: getRenderValue
|
|
1554
1564
|
}) : null;
|
|
1555
1565
|
}
|
|
1556
1566
|
};
|
|
@@ -2533,8 +2543,10 @@ const Sorting = {
|
|
|
2533
2543
|
// })
|
|
2534
2544
|
// return
|
|
2535
2545
|
// }
|
|
2546
|
+
// this needs to be outside of instance.setSorting to be in sync with rerender
|
|
2547
|
+
const nextSortingOrder = column.getNextSortingOrder();
|
|
2536
2548
|
instance.setSorting(old => {
|
|
2537
|
-
var
|
|
2549
|
+
var _instance$options$ena, _instance$options$ena2;
|
|
2538
2550
|
|
|
2539
2551
|
// Find any existing sorting for this column
|
|
2540
2552
|
const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
@@ -2559,30 +2571,29 @@ const Sorting = {
|
|
|
2559
2571
|
} else {
|
|
2560
2572
|
sortAction = 'replace';
|
|
2561
2573
|
}
|
|
2562
|
-
}
|
|
2574
|
+
} // Handle toggle states that will remove the sorting
|
|
2563
2575
|
|
|
2564
|
-
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
|
|
2565
2576
|
|
|
2566
2577
|
if (sortAction === 'toggle' && ( // Must be toggling
|
|
2567
2578
|
(_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
|
|
2568
2579
|
!hasDescDefined && ( // Must not be setting desc
|
|
2569
|
-
multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) &&
|
|
2570
|
-
|
|
2571
|
-
|
|
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
|
+
) {
|
|
2572
2583
|
sortAction = 'remove';
|
|
2573
2584
|
}
|
|
2574
2585
|
|
|
2575
2586
|
if (sortAction === 'replace') {
|
|
2576
2587
|
newSorting = [{
|
|
2577
2588
|
id: column.id,
|
|
2578
|
-
desc: hasDescDefined ? desc :
|
|
2589
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2579
2590
|
}];
|
|
2580
2591
|
} else if (sortAction === 'add' && old != null && old.length) {
|
|
2581
2592
|
var _instance$options$max;
|
|
2582
2593
|
|
|
2583
2594
|
newSorting = [...old, {
|
|
2584
2595
|
id: column.id,
|
|
2585
|
-
desc: hasDescDefined ? desc :
|
|
2596
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2586
2597
|
}]; // Take latest n columns
|
|
2587
2598
|
|
|
2588
2599
|
newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
|
|
@@ -2591,7 +2602,7 @@ const Sorting = {
|
|
|
2591
2602
|
newSorting = old.map(d => {
|
|
2592
2603
|
if (d.id === column.id) {
|
|
2593
2604
|
return { ...d,
|
|
2594
|
-
desc: hasDescDefined ? desc :
|
|
2605
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2595
2606
|
};
|
|
2596
2607
|
}
|
|
2597
2608
|
|
|
@@ -2604,6 +2615,23 @@ const Sorting = {
|
|
|
2604
2615
|
return newSorting;
|
|
2605
2616
|
});
|
|
2606
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
|
+
},
|
|
2607
2635
|
getCanSort: () => {
|
|
2608
2636
|
var _column$columnDef$ena, _instance$options$ena3;
|
|
2609
2637
|
|
|
@@ -3053,6 +3081,12 @@ function createTable$1(_, __, options) {
|
|
|
3053
3081
|
}
|
|
3054
3082
|
|
|
3055
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
|
+
|
|
3056
3090
|
const cell = {
|
|
3057
3091
|
id: row.id + "_" + column.id,
|
|
3058
3092
|
row,
|
|
@@ -3064,7 +3098,7 @@ function createCell(instance, row, column, columnId) {
|
|
|
3064
3098
|
column,
|
|
3065
3099
|
row,
|
|
3066
3100
|
cell: cell,
|
|
3067
|
-
getValue:
|
|
3101
|
+
getValue: getRenderValue
|
|
3068
3102
|
}) : null;
|
|
3069
3103
|
}
|
|
3070
3104
|
};
|
|
@@ -3848,6 +3882,7 @@ function useTableInstance(table, options) {
|
|
|
3848
3882
|
onStateChange: () => {},
|
|
3849
3883
|
// noop
|
|
3850
3884
|
render,
|
|
3885
|
+
renderFallbackValue: null,
|
|
3851
3886
|
...options
|
|
3852
3887
|
}; // Create a new table instance and store it in state
|
|
3853
3888
|
|