@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.
@@ -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(old, updater);
3509
+ var newState = functionalUpdate(updater, old);
3485
3510
 
3486
- if (!instance.options.paginateRowsFn) {
3487
- var _instance$getPreExpan;
3511
+ if (instance.options.paginateRowsFn) {
3512
+ var _instance$getPrePagin;
3488
3513
 
3489
- return _extends({}, old, {
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 old;
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 newPageIndex = functionalUpdate(updater, old.pageIndex);
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: Math.min(Math.max(0, newPageIndex), maxPageIndex)
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: Math.max(-1, functionalUpdate(updater, old.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
- gotoPreviousPage: function gotoPreviousPage() {
3579
- return instance.setPageIndex == null ? void 0 : instance.setPageIndex(function (old) {
3608
+ previousPage: function previousPage() {
3609
+ return instance.setPageIndex(function (old) {
3580
3610
  return old - 1;
3581
3611
  });
3582
3612
  },
3583
- gotoNextPage: function gotoNextPage() {
3584
- return instance.setPageIndex == null ? void 0 : instance.setPageIndex(function (old) {
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.getExpandedRowModel();
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