@tanstack/table-core 8.0.0-beta.3 → 8.0.0-beta.6
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/Expanding.js +4 -7
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Grouping.js +14 -4
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/RowSelection.js +4 -4
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +28 -10
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +19 -5
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/esm/index.js +76 -31
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +318 -318
- package/build/types/core/instance.d.ts +1 -0
- package/build/types/features/RowSelection.d.ts +2 -2
- package/build/types/features/Sorting.d.ts +1 -0
- package/build/types/types.d.ts +1 -1
- package/build/umd/index.development.js +76 -31
- 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/Expanding.ts +4 -8
- package/src/features/Grouping.ts +14 -3
- package/src/features/RowSelection.ts +8 -6
- package/src/features/Sorting.ts +28 -15
- package/src/types.ts +1 -1
- package/src/utils/getPaginationRowModel.ts +21 -6
|
@@ -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;
|
|
@@ -28,8 +28,8 @@ export declare type RowSelectionInstance<TGenerics extends TableGenerics> = {
|
|
|
28
28
|
getIsAllPageRowsSelected: () => boolean;
|
|
29
29
|
getIsSomeRowsSelected: () => boolean;
|
|
30
30
|
getIsSomePageRowsSelected: () => boolean;
|
|
31
|
-
toggleAllRowsSelected: (value
|
|
32
|
-
toggleAllPageRowsSelected: (value
|
|
31
|
+
toggleAllRowsSelected: (value?: boolean) => void;
|
|
32
|
+
toggleAllPageRowsSelected: (value?: boolean) => void;
|
|
33
33
|
getPreSelectedRowModel: () => RowModel<TGenerics>;
|
|
34
34
|
getSelectedRowModel: () => RowModel<TGenerics>;
|
|
35
35
|
getFilteredSelectedRowModel: () => RowModel<TGenerics>;
|
|
@@ -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;
|
|
@@ -818,7 +818,6 @@
|
|
|
818
818
|
getDefaultOptions: instance => {
|
|
819
819
|
return {
|
|
820
820
|
onExpandedChange: makeStateUpdater('expanded', instance),
|
|
821
|
-
autoResetExpanded: true,
|
|
822
821
|
paginateExpandedRows: true
|
|
823
822
|
};
|
|
824
823
|
},
|
|
@@ -827,6 +826,8 @@
|
|
|
827
826
|
let queued = false;
|
|
828
827
|
return {
|
|
829
828
|
_autoResetExpanded: () => {
|
|
829
|
+
var _ref, _instance$options$aut;
|
|
830
|
+
|
|
830
831
|
if (!registered) {
|
|
831
832
|
instance._queue(() => {
|
|
832
833
|
registered = true;
|
|
@@ -835,11 +836,7 @@
|
|
|
835
836
|
return;
|
|
836
837
|
}
|
|
837
838
|
|
|
838
|
-
if (instance.options.autoResetAll
|
|
839
|
-
return;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
|
|
839
|
+
if ((_ref = (_instance$options$aut = instance.options.autoResetAll) != null ? _instance$options$aut : instance.options.autoResetExpanded) != null ? _ref : !instance.options.manualExpanding) {
|
|
843
840
|
if (queued) return;
|
|
844
841
|
queued = true;
|
|
845
842
|
|
|
@@ -903,7 +900,7 @@
|
|
|
903
900
|
});
|
|
904
901
|
return maxDepth;
|
|
905
902
|
},
|
|
906
|
-
getPreExpandedRowModel: () => instance.
|
|
903
|
+
getPreExpandedRowModel: () => instance.getSortedRowModel(),
|
|
907
904
|
getExpandedRowModel: () => {
|
|
908
905
|
if (!instance._getExpandedRowModel && instance.options.getExpandedRowModel) {
|
|
909
906
|
instance._getExpandedRowModel = instance.options.getExpandedRowModel(instance);
|
|
@@ -1504,7 +1501,7 @@
|
|
|
1504
1501
|
|
|
1505
1502
|
instance.setGrouping(defaultState ? [] : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.grouping) != null ? _instance$initialStat : []);
|
|
1506
1503
|
},
|
|
1507
|
-
getPreGroupedRowModel: () => instance.
|
|
1504
|
+
getPreGroupedRowModel: () => instance.getFilteredRowModel(),
|
|
1508
1505
|
getGroupedRowModel: () => {
|
|
1509
1506
|
if (!instance._getGroupedRowModel && instance.options.getGroupedRowModel) {
|
|
1510
1507
|
instance._getGroupedRowModel = instance.options.getGroupedRowModel(instance);
|
|
@@ -1525,6 +1522,12 @@
|
|
|
1525
1522
|
};
|
|
1526
1523
|
},
|
|
1527
1524
|
createCell: (cell, column, row, instance) => {
|
|
1525
|
+
const getRenderValue = () => {
|
|
1526
|
+
var _cell$getValue;
|
|
1527
|
+
|
|
1528
|
+
return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
|
|
1529
|
+
};
|
|
1530
|
+
|
|
1528
1531
|
return {
|
|
1529
1532
|
getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
|
|
1530
1533
|
getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
|
|
@@ -1534,15 +1537,19 @@
|
|
|
1534
1537
|
return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
|
|
1535
1538
|
},
|
|
1536
1539
|
renderAggregatedCell: () => {
|
|
1537
|
-
|
|
1540
|
+
{
|
|
1541
|
+
if (!column.columnDef.aggregatedCell) {
|
|
1542
|
+
console.warn('A columnDef.aggregatedCell template is recommended for displaying aggregated values.');
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1538
1545
|
|
|
1539
|
-
const template =
|
|
1546
|
+
const template = column.columnDef.aggregatedCell || column.columnDef.cell;
|
|
1540
1547
|
return template ? instance._render(template, {
|
|
1541
1548
|
instance,
|
|
1542
1549
|
column,
|
|
1543
1550
|
row,
|
|
1544
1551
|
cell,
|
|
1545
|
-
getValue:
|
|
1552
|
+
getValue: getRenderValue
|
|
1546
1553
|
}) : null;
|
|
1547
1554
|
}
|
|
1548
1555
|
};
|
|
@@ -2012,11 +2019,11 @@
|
|
|
2012
2019
|
});
|
|
2013
2020
|
},
|
|
2014
2021
|
toggleAllPageRowsSelected: value => instance.setRowSelection(old => {
|
|
2015
|
-
typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
|
|
2022
|
+
const resolvedValue = typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
|
|
2016
2023
|
const rowSelection = { ...old
|
|
2017
2024
|
};
|
|
2018
2025
|
instance.getRowModel().rows.forEach(row => {
|
|
2019
|
-
mutateRowIsSelected(rowSelection, row.id,
|
|
2026
|
+
mutateRowIsSelected(rowSelection, row.id, resolvedValue, instance);
|
|
2020
2027
|
});
|
|
2021
2028
|
return rowSelection;
|
|
2022
2029
|
}),
|
|
@@ -2107,7 +2114,7 @@
|
|
|
2107
2114
|
return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugTable;
|
|
2108
2115
|
}
|
|
2109
2116
|
}),
|
|
2110
|
-
getGroupedSelectedRowModel: memo(() => [instance.getState().rowSelection, instance.
|
|
2117
|
+
getGroupedSelectedRowModel: memo(() => [instance.getState().rowSelection, instance.getSortedRowModel()], (rowSelection, rowModel) => {
|
|
2111
2118
|
if (!Object.keys(rowSelection).length) {
|
|
2112
2119
|
return {
|
|
2113
2120
|
rows: [],
|
|
@@ -2171,7 +2178,7 @@
|
|
|
2171
2178
|
},
|
|
2172
2179
|
getIsSomePageRowsSelected: () => {
|
|
2173
2180
|
const paginationFlatRows = instance.getPaginationRowModel().flatRows;
|
|
2174
|
-
return instance.getIsAllPageRowsSelected() ? false :
|
|
2181
|
+
return instance.getIsAllPageRowsSelected() ? false : paginationFlatRows.some(d => d.getIsSelected() || d.getIsSomeSelected());
|
|
2175
2182
|
},
|
|
2176
2183
|
getToggleAllRowsSelectedHandler: () => {
|
|
2177
2184
|
return e => {
|
|
@@ -2525,8 +2532,10 @@
|
|
|
2525
2532
|
// })
|
|
2526
2533
|
// return
|
|
2527
2534
|
// }
|
|
2535
|
+
// this needs to be outside of instance.setSorting to be in sync with rerender
|
|
2536
|
+
const nextSortingOrder = column.getNextSortingOrder();
|
|
2528
2537
|
instance.setSorting(old => {
|
|
2529
|
-
var
|
|
2538
|
+
var _instance$options$ena, _instance$options$ena2;
|
|
2530
2539
|
|
|
2531
2540
|
// Find any existing sorting for this column
|
|
2532
2541
|
const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
@@ -2551,30 +2560,29 @@
|
|
|
2551
2560
|
} else {
|
|
2552
2561
|
sortAction = 'replace';
|
|
2553
2562
|
}
|
|
2554
|
-
}
|
|
2563
|
+
} // Handle toggle states that will remove the sorting
|
|
2555
2564
|
|
|
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
2565
|
|
|
2558
2566
|
if (sortAction === 'toggle' && ( // Must be toggling
|
|
2559
2567
|
(_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
|
|
2560
2568
|
!hasDescDefined && ( // Must not be setting desc
|
|
2561
|
-
multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) &&
|
|
2562
|
-
|
|
2563
|
-
|
|
2569
|
+
multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && // If multi, don't allow if enableMultiRemove
|
|
2570
|
+
!nextSortingOrder // Finally, detect if it should indeed be removed
|
|
2571
|
+
) {
|
|
2564
2572
|
sortAction = 'remove';
|
|
2565
2573
|
}
|
|
2566
2574
|
|
|
2567
2575
|
if (sortAction === 'replace') {
|
|
2568
2576
|
newSorting = [{
|
|
2569
2577
|
id: column.id,
|
|
2570
|
-
desc: hasDescDefined ? desc :
|
|
2578
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2571
2579
|
}];
|
|
2572
2580
|
} else if (sortAction === 'add' && old != null && old.length) {
|
|
2573
2581
|
var _instance$options$max;
|
|
2574
2582
|
|
|
2575
2583
|
newSorting = [...old, {
|
|
2576
2584
|
id: column.id,
|
|
2577
|
-
desc: hasDescDefined ? desc :
|
|
2585
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2578
2586
|
}]; // Take latest n columns
|
|
2579
2587
|
|
|
2580
2588
|
newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
|
|
@@ -2583,7 +2591,7 @@
|
|
|
2583
2591
|
newSorting = old.map(d => {
|
|
2584
2592
|
if (d.id === column.id) {
|
|
2585
2593
|
return { ...d,
|
|
2586
|
-
desc: hasDescDefined ? desc :
|
|
2594
|
+
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2587
2595
|
};
|
|
2588
2596
|
}
|
|
2589
2597
|
|
|
@@ -2596,6 +2604,23 @@
|
|
|
2596
2604
|
return newSorting;
|
|
2597
2605
|
});
|
|
2598
2606
|
},
|
|
2607
|
+
getNextSortingOrder: () => {
|
|
2608
|
+
var _ref2, _column$columnDef$sor;
|
|
2609
|
+
|
|
2610
|
+
const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc';
|
|
2611
|
+
const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
|
|
2612
|
+
const isSorted = column.getIsSorted();
|
|
2613
|
+
|
|
2614
|
+
if (!isSorted) {
|
|
2615
|
+
return firstSortDirection;
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
if (isSorted === firstSortDirection) {
|
|
2619
|
+
return isSorted === 'desc' ? 'asc' : 'desc';
|
|
2620
|
+
} else {
|
|
2621
|
+
return false;
|
|
2622
|
+
}
|
|
2623
|
+
},
|
|
2599
2624
|
getCanSort: () => {
|
|
2600
2625
|
var _column$columnDef$ena, _instance$options$ena3;
|
|
2601
2626
|
|
|
@@ -2639,7 +2664,7 @@
|
|
|
2639
2664
|
|
|
2640
2665
|
instance.setSorting(defaultState ? [] : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.sorting) != null ? _instance$initialStat : []);
|
|
2641
2666
|
},
|
|
2642
|
-
getPreSortedRowModel: () => instance.
|
|
2667
|
+
getPreSortedRowModel: () => instance.getGroupedRowModel(),
|
|
2643
2668
|
getSortedRowModel: () => {
|
|
2644
2669
|
if (!instance._getSortedRowModel && instance.options.getSortedRowModel) {
|
|
2645
2670
|
instance._getSortedRowModel = instance.options.getSortedRowModel(instance);
|
|
@@ -3043,6 +3068,12 @@
|
|
|
3043
3068
|
}
|
|
3044
3069
|
|
|
3045
3070
|
function createCell(instance, row, column, columnId) {
|
|
3071
|
+
const getRenderValue = () => {
|
|
3072
|
+
var _cell$getValue;
|
|
3073
|
+
|
|
3074
|
+
return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
|
|
3075
|
+
};
|
|
3076
|
+
|
|
3046
3077
|
const cell = {
|
|
3047
3078
|
id: row.id + "_" + column.id,
|
|
3048
3079
|
row,
|
|
@@ -3054,7 +3085,7 @@
|
|
|
3054
3085
|
column,
|
|
3055
3086
|
row,
|
|
3056
3087
|
cell: cell,
|
|
3057
|
-
getValue:
|
|
3088
|
+
getValue: getRenderValue
|
|
3058
3089
|
}) : null;
|
|
3059
3090
|
}
|
|
3060
3091
|
};
|
|
@@ -3783,20 +3814,34 @@
|
|
|
3783
3814
|
const pageStart = pageSize * pageIndex;
|
|
3784
3815
|
const pageEnd = pageStart + pageSize;
|
|
3785
3816
|
rows = rows.slice(pageStart, pageEnd);
|
|
3817
|
+
let paginatedRowModel;
|
|
3786
3818
|
|
|
3787
3819
|
if (!instance.options.paginateExpandedRows) {
|
|
3788
|
-
|
|
3820
|
+
paginatedRowModel = expandRows({
|
|
3789
3821
|
rows,
|
|
3790
3822
|
flatRows,
|
|
3791
3823
|
rowsById
|
|
3792
3824
|
});
|
|
3825
|
+
} else {
|
|
3826
|
+
paginatedRowModel = {
|
|
3827
|
+
rows,
|
|
3828
|
+
flatRows,
|
|
3829
|
+
rowsById
|
|
3830
|
+
};
|
|
3793
3831
|
}
|
|
3794
3832
|
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3833
|
+
paginatedRowModel.flatRows = [];
|
|
3834
|
+
|
|
3835
|
+
const handleRow = row => {
|
|
3836
|
+
paginatedRowModel.flatRows.push(row);
|
|
3837
|
+
|
|
3838
|
+
if (row.subRows.length) {
|
|
3839
|
+
row.subRows.forEach(handleRow);
|
|
3840
|
+
}
|
|
3799
3841
|
};
|
|
3842
|
+
|
|
3843
|
+
paginatedRowModel.rows.forEach(handleRow);
|
|
3844
|
+
return paginatedRowModel;
|
|
3800
3845
|
}, {
|
|
3801
3846
|
key: 'getPaginationRowModel',
|
|
3802
3847
|
debug: () => {
|