@tanstack/table-core 8.2.0 → 8.2.3
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/column.js.map +1 -1
- package/build/cjs/core/row.js.map +1 -1
- package/build/cjs/features/RowSelection.js +7 -1
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +33 -26
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/sortingFns.js +6 -1
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +1 -1
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/esm/index.js +47 -29
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +307 -307
- package/build/types/index.d.ts +3 -2
- package/build/umd/index.development.js +47 -29
- 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/column.ts +1 -1
- package/src/core/row.ts +2 -2
- package/src/features/RowSelection.ts +6 -1
- package/src/features/Sorting.ts +38 -27
- package/src/sortingFns.ts +7 -4
- package/src/utils/getCoreRowModel.ts +1 -1
- package/src/utils/getGroupedRowModel.ts +7 -1
package/build/types/index.d.ts
CHANGED
|
@@ -333,6 +333,7 @@ declare type SortingColumn<TData extends RowData> = {
|
|
|
333
333
|
getAutoSortingFn: () => SortingFn<TData>;
|
|
334
334
|
getAutoSortDir: () => SortDirection;
|
|
335
335
|
getSortingFn: () => SortingFn<TData>;
|
|
336
|
+
getFirstSortDir: () => SortDirection;
|
|
336
337
|
getNextSortingOrder: () => SortDirection | false;
|
|
337
338
|
getCanSort: () => boolean;
|
|
338
339
|
getCanMultiSort: () => boolean;
|
|
@@ -613,7 +614,7 @@ declare function isSubRowSelected<TData extends RowData>(row: Row<TData>, select
|
|
|
613
614
|
declare type CoreRow<TData extends RowData> = {
|
|
614
615
|
id: string;
|
|
615
616
|
index: number;
|
|
616
|
-
original
|
|
617
|
+
original: TData;
|
|
617
618
|
depth: number;
|
|
618
619
|
_valuesCache: Record<string, unknown>;
|
|
619
620
|
getValue: <TValue>(columnId: string) => TValue;
|
|
@@ -624,7 +625,7 @@ declare type CoreRow<TData extends RowData> = {
|
|
|
624
625
|
getAllCells: () => Cell<TData, unknown>[];
|
|
625
626
|
_getAllCellsByColumnId: () => Record<string, Cell<TData, unknown>>;
|
|
626
627
|
};
|
|
627
|
-
declare const createRow: <TData extends unknown>(table: Table<TData>, id: string, original: TData
|
|
628
|
+
declare const createRow: <TData extends unknown>(table: Table<TData>, id: string, original: TData, rowIndex: number, depth: number, subRows?: Row<TData>[] | undefined) => Row<TData>;
|
|
628
629
|
|
|
629
630
|
interface TableMeta {
|
|
630
631
|
}
|
|
@@ -1983,6 +1983,10 @@
|
|
|
1983
1983
|
|
|
1984
1984
|
if (value) {
|
|
1985
1985
|
preGroupedFlatRows.forEach(row => {
|
|
1986
|
+
if (!row.getCanSelect()) {
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1986
1990
|
rowSelection[row.id] = true;
|
|
1987
1991
|
});
|
|
1988
1992
|
} else {
|
|
@@ -2257,7 +2261,9 @@
|
|
|
2257
2261
|
Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key]);
|
|
2258
2262
|
}
|
|
2259
2263
|
|
|
2260
|
-
|
|
2264
|
+
if (row.getCanSelect()) {
|
|
2265
|
+
selectedRowIds[id] = true;
|
|
2266
|
+
}
|
|
2261
2267
|
} else {
|
|
2262
2268
|
delete selectedRowIds[id];
|
|
2263
2269
|
} // }
|
|
@@ -2353,7 +2359,12 @@
|
|
|
2353
2359
|
};
|
|
2354
2360
|
|
|
2355
2361
|
const datetime = (rowA, rowB, columnId) => {
|
|
2356
|
-
|
|
2362
|
+
const a = rowA.getValue(columnId);
|
|
2363
|
+
const b = rowB.getValue(columnId); // Can handle nullish values
|
|
2364
|
+
// Use > and < because == (and ===) doesn't work with
|
|
2365
|
+
// Date objects (would require calling getTime()).
|
|
2366
|
+
|
|
2367
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
2357
2368
|
};
|
|
2358
2369
|
|
|
2359
2370
|
const basic = (rowA, rowB, columnId) => {
|
|
@@ -2514,18 +2525,17 @@
|
|
|
2514
2525
|
// }
|
|
2515
2526
|
// this needs to be outside of table.setSorting to be in sync with rerender
|
|
2516
2527
|
const nextSortingOrder = column.getNextSortingOrder();
|
|
2528
|
+
const hasManualValue = typeof desc !== 'undefined' && desc !== null;
|
|
2517
2529
|
table.setSorting(old => {
|
|
2518
|
-
var _table$options$enable, _table$options$enable2;
|
|
2519
|
-
|
|
2520
2530
|
// Find any existing sorting for this column
|
|
2521
2531
|
const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
2522
2532
|
const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
|
|
2523
|
-
const hasDescDefined = typeof desc !== 'undefined' && desc !== null;
|
|
2524
2533
|
let newSorting = []; // What should we do with this sort action?
|
|
2525
2534
|
|
|
2526
2535
|
let sortAction;
|
|
2536
|
+
let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'; // Multi-mode
|
|
2527
2537
|
|
|
2528
|
-
if (column.getCanMultiSort() && multi) {
|
|
2538
|
+
if (old != null && old.length && column.getCanMultiSort() && multi) {
|
|
2529
2539
|
if (existingSorting) {
|
|
2530
2540
|
sortAction = 'toggle';
|
|
2531
2541
|
} else {
|
|
@@ -2543,63 +2553,71 @@
|
|
|
2543
2553
|
} // Handle toggle states that will remove the sorting
|
|
2544
2554
|
|
|
2545
2555
|
|
|
2546
|
-
if (sortAction === 'toggle'
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2556
|
+
if (sortAction === 'toggle') {
|
|
2557
|
+
// If we are "actually" toggling (not a manual set value), should we remove the sorting?
|
|
2558
|
+
if (!hasManualValue) {
|
|
2559
|
+
// Is our intention to remove?
|
|
2560
|
+
if (!nextSortingOrder) {
|
|
2561
|
+
sortAction = 'remove';
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2553
2564
|
}
|
|
2554
2565
|
|
|
2555
|
-
if (sortAction === '
|
|
2556
|
-
newSorting = [{
|
|
2557
|
-
id: column.id,
|
|
2558
|
-
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2559
|
-
}];
|
|
2560
|
-
} else if (sortAction === 'add' && old != null && old.length) {
|
|
2566
|
+
if (sortAction === 'add') {
|
|
2561
2567
|
var _table$options$maxMul;
|
|
2562
2568
|
|
|
2563
2569
|
newSorting = [...old, {
|
|
2564
2570
|
id: column.id,
|
|
2565
|
-
desc:
|
|
2571
|
+
desc: nextDesc
|
|
2566
2572
|
}]; // Take latest n columns
|
|
2567
2573
|
|
|
2568
2574
|
newSorting.splice(0, newSorting.length - ((_table$options$maxMul = table.options.maxMultiSortColCount) != null ? _table$options$maxMul : Number.MAX_SAFE_INTEGER));
|
|
2569
|
-
} else if (sortAction === 'toggle'
|
|
2575
|
+
} else if (sortAction === 'toggle') {
|
|
2570
2576
|
// This flips (or sets) the
|
|
2571
2577
|
newSorting = old.map(d => {
|
|
2572
2578
|
if (d.id === column.id) {
|
|
2573
2579
|
return { ...d,
|
|
2574
|
-
desc:
|
|
2580
|
+
desc: nextDesc
|
|
2575
2581
|
};
|
|
2576
2582
|
}
|
|
2577
2583
|
|
|
2578
2584
|
return d;
|
|
2579
2585
|
});
|
|
2580
|
-
} else if (sortAction === 'remove'
|
|
2586
|
+
} else if (sortAction === 'remove') {
|
|
2581
2587
|
newSorting = old.filter(d => d.id !== column.id);
|
|
2588
|
+
} else {
|
|
2589
|
+
newSorting = [{
|
|
2590
|
+
id: column.id,
|
|
2591
|
+
desc: nextDesc
|
|
2592
|
+
}];
|
|
2582
2593
|
}
|
|
2583
2594
|
|
|
2584
2595
|
return newSorting;
|
|
2585
2596
|
});
|
|
2586
2597
|
},
|
|
2587
|
-
|
|
2598
|
+
getFirstSortDir: () => {
|
|
2588
2599
|
var _ref, _column$columnDef$sor;
|
|
2589
2600
|
|
|
2590
2601
|
const sortDescFirst = (_ref = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : table.options.sortDescFirst) != null ? _ref : column.getAutoSortDir() === 'desc';
|
|
2591
|
-
|
|
2602
|
+
return sortDescFirst ? 'desc' : 'asc';
|
|
2603
|
+
},
|
|
2604
|
+
getNextSortingOrder: multi => {
|
|
2605
|
+
var _table$options$enable, _table$options$enable2;
|
|
2606
|
+
|
|
2607
|
+
const firstSortDirection = column.getFirstSortDir();
|
|
2592
2608
|
const isSorted = column.getIsSorted();
|
|
2593
2609
|
|
|
2594
2610
|
if (!isSorted) {
|
|
2595
2611
|
return firstSortDirection;
|
|
2596
2612
|
}
|
|
2597
2613
|
|
|
2598
|
-
if (isSorted
|
|
2599
|
-
|
|
2600
|
-
|
|
2614
|
+
if (isSorted !== firstSortDirection && ((_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && ( // If enableSortRemove, enable in general
|
|
2615
|
+
multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) // If multi, don't allow if enableMultiRemove))
|
|
2616
|
+
) {
|
|
2601
2617
|
return false;
|
|
2602
2618
|
}
|
|
2619
|
+
|
|
2620
|
+
return isSorted === 'desc' ? 'asc' : 'desc';
|
|
2603
2621
|
},
|
|
2604
2622
|
getCanSort: () => {
|
|
2605
2623
|
var _column$columnDef$ena, _table$options$enable3;
|
|
@@ -3563,7 +3581,7 @@
|
|
|
3563
3581
|
const subRows = groupUpRecursively(groupedRows, depth + 1, id); // Flatten the leaf rows of the rows in this group
|
|
3564
3582
|
|
|
3565
3583
|
const leafRows = depth ? flattenBy(groupedRows, row => row.subRows) : groupedRows;
|
|
3566
|
-
const row = createRow(table, id,
|
|
3584
|
+
const row = createRow(table, id, leafRows[0].original, index, depth);
|
|
3567
3585
|
Object.assign(row, {
|
|
3568
3586
|
groupingColumnId: columnId,
|
|
3569
3587
|
groupingValue,
|