@tanstack/react-table 8.0.0-alpha.3 → 8.0.0-alpha.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.js +1 -1
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/features/Pagination.js +22 -18
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/index.js +2 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/paginateRowsFn.js +44 -0
- package/build/cjs/utils/paginateRowsFn.js.map +1 -0
- package/build/esm/index.js +50 -20
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +254 -222
- package/build/types/core.d.ts +1 -1
- package/build/types/features/Pagination.d.ts +5 -4
- package/build/types/index.d.ts +1 -0
- package/build/umd/index.development.js +50 -19
- 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.tsx +2 -3
- package/src/features/Pagination.ts +43 -30
- package/src/index.tsx +1 -0
package/build/esm/index.js
CHANGED
|
@@ -655,6 +655,32 @@ function expandRowsFn(instance, sortedRowModel) {
|
|
|
655
655
|
};
|
|
656
656
|
}
|
|
657
657
|
|
|
658
|
+
function paginateRowsFn(instance, rowModel) {
|
|
659
|
+
var _instance$getState$pa = instance.getState().pagination,
|
|
660
|
+
pageSize = _instance$getState$pa.pageSize,
|
|
661
|
+
pageIndex = _instance$getState$pa.pageIndex;
|
|
662
|
+
var rows = rowModel.rows,
|
|
663
|
+
flatRows = rowModel.flatRows,
|
|
664
|
+
rowsById = rowModel.rowsById;
|
|
665
|
+
var pageStart = pageSize * pageIndex;
|
|
666
|
+
var pageEnd = pageStart + pageSize;
|
|
667
|
+
rows = rows.slice(pageStart, pageEnd);
|
|
668
|
+
|
|
669
|
+
if (!instance.options.paginateExpandedRows) {
|
|
670
|
+
return expandRowsFn(instance, {
|
|
671
|
+
rows: rows,
|
|
672
|
+
flatRows: flatRows,
|
|
673
|
+
rowsById: rowsById
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
return {
|
|
678
|
+
rows: rows,
|
|
679
|
+
flatRows: flatRows,
|
|
680
|
+
rowsById: rowsById
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
|
|
658
684
|
//
|
|
659
685
|
function getInitialState$9() {
|
|
660
686
|
return {
|
|
@@ -3451,8 +3477,7 @@ function getInitialState$1() {
|
|
|
3451
3477
|
return {
|
|
3452
3478
|
pagination: {
|
|
3453
3479
|
pageIndex: 0,
|
|
3454
|
-
pageSize: 10
|
|
3455
|
-
pageCount: -1
|
|
3480
|
+
pageSize: 10
|
|
3456
3481
|
}
|
|
3457
3482
|
};
|
|
3458
3483
|
}
|
|
@@ -3481,17 +3506,15 @@ function getInstance$1(instance) {
|
|
|
3481
3506
|
},
|
|
3482
3507
|
setPagination: function setPagination(updater) {
|
|
3483
3508
|
var safeUpdater = function safeUpdater(old) {
|
|
3484
|
-
functionalUpdate(
|
|
3509
|
+
var newState = functionalUpdate(updater, old);
|
|
3485
3510
|
|
|
3486
|
-
if (
|
|
3487
|
-
var _instance$
|
|
3511
|
+
if (instance.options.paginateRowsFn) {
|
|
3512
|
+
var _instance$getPrePagin;
|
|
3488
3513
|
|
|
3489
|
-
|
|
3490
|
-
pageCount: (_instance$getPreExpan = instance.getPreExpandedRows()) != null && _instance$getPreExpan.length ? Math.ceil(instance.getPreExpandedRows().length / instance.getState().pagination.pageSize) : 0
|
|
3491
|
-
});
|
|
3514
|
+
newState.pageCount = (_instance$getPrePagin = instance.getPrePaginationRows()) != null && _instance$getPrePagin.length ? Math.ceil(instance.getPrePaginationRows().length / instance.getState().pagination.pageSize) : 0;
|
|
3492
3515
|
}
|
|
3493
3516
|
|
|
3494
|
-
return
|
|
3517
|
+
return newState;
|
|
3495
3518
|
};
|
|
3496
3519
|
|
|
3497
3520
|
return instance.options.onPaginationChange == null ? void 0 : instance.options.onPaginationChange(safeUpdater, functionalUpdate(safeUpdater, instance.getState().pagination));
|
|
@@ -3507,10 +3530,11 @@ function getInstance$1(instance) {
|
|
|
3507
3530
|
},
|
|
3508
3531
|
setPageIndex: function setPageIndex(updater) {
|
|
3509
3532
|
instance.setPagination(function (old) {
|
|
3510
|
-
var
|
|
3511
|
-
var maxPageIndex = old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
|
|
3533
|
+
var pageIndex = functionalUpdate(updater, old.pageIndex);
|
|
3534
|
+
var maxPageIndex = old.pageCount && old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
|
|
3535
|
+
pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
|
|
3512
3536
|
return _extends({}, old, {
|
|
3513
|
-
pageIndex:
|
|
3537
|
+
pageIndex: pageIndex
|
|
3514
3538
|
});
|
|
3515
3539
|
});
|
|
3516
3540
|
},
|
|
@@ -3535,8 +3559,14 @@ function getInstance$1(instance) {
|
|
|
3535
3559
|
},
|
|
3536
3560
|
setPageCount: function setPageCount(updater) {
|
|
3537
3561
|
return instance.setPagination(function (old) {
|
|
3562
|
+
var newPageCount = functionalUpdate(updater, old.pageCount);
|
|
3563
|
+
|
|
3564
|
+
if (typeof newPageCount === 'number') {
|
|
3565
|
+
newPageCount = Math.max(-1, newPageCount);
|
|
3566
|
+
}
|
|
3567
|
+
|
|
3538
3568
|
return _extends({}, old, {
|
|
3539
|
-
pageCount:
|
|
3569
|
+
pageCount: newPageCount
|
|
3540
3570
|
});
|
|
3541
3571
|
});
|
|
3542
3572
|
},
|
|
@@ -3545,7 +3575,7 @@ function getInstance$1(instance) {
|
|
|
3545
3575
|
}, function (pageSize, pageCount) {
|
|
3546
3576
|
var pageOptions = [];
|
|
3547
3577
|
|
|
3548
|
-
if (pageCount > 0) {
|
|
3578
|
+
if (pageCount && pageCount > 0) {
|
|
3549
3579
|
pageOptions = [].concat(new Array(pageCount)).fill(null).map(function (_, i) {
|
|
3550
3580
|
return i;
|
|
3551
3581
|
});
|
|
@@ -3575,13 +3605,13 @@ function getInstance$1(instance) {
|
|
|
3575
3605
|
|
|
3576
3606
|
return pageIndex < Math.ceil(instance.getPrePaginationRows().length / pageSize) - 1;
|
|
3577
3607
|
},
|
|
3578
|
-
|
|
3579
|
-
return instance.setPageIndex
|
|
3608
|
+
previousPage: function previousPage() {
|
|
3609
|
+
return instance.setPageIndex(function (old) {
|
|
3580
3610
|
return old - 1;
|
|
3581
3611
|
});
|
|
3582
3612
|
},
|
|
3583
|
-
|
|
3584
|
-
return instance.setPageIndex
|
|
3613
|
+
nextPage: function nextPage() {
|
|
3614
|
+
return instance.setPageIndex(function (old) {
|
|
3585
3615
|
return old + 1;
|
|
3586
3616
|
});
|
|
3587
3617
|
},
|
|
@@ -4555,7 +4585,7 @@ function createTableInstance(options, rerender) {
|
|
|
4555
4585
|
// The final calls start at the bottom of the model,
|
|
4556
4586
|
// expanded rows, which then work their way up
|
|
4557
4587
|
getRowModel: function getRowModel() {
|
|
4558
|
-
return instance.
|
|
4588
|
+
return instance.getPaginationRowModel();
|
|
4559
4589
|
},
|
|
4560
4590
|
getRows: function getRows() {
|
|
4561
4591
|
return instance.getRowModel().rows;
|
|
@@ -4743,5 +4773,5 @@ function createTable() {
|
|
|
4743
4773
|
};
|
|
4744
4774
|
}
|
|
4745
4775
|
|
|
4746
|
-
export { columnFilterRowsFn, createTable, expandRowsFn, globalFilterRowsFn, groupRowsFn, sortRowsFn };
|
|
4776
|
+
export { columnFilterRowsFn, createTable, expandRowsFn, globalFilterRowsFn, groupRowsFn, paginateRowsFn, sortRowsFn };
|
|
4747
4777
|
//# sourceMappingURL=index.js.map
|