@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.
@@ -76,7 +76,7 @@ export declare type CoreColumnDef<TData, TValue, TFilterFns, TSortingFns, TAggre
76
76
  header: Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
77
77
  column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
78
78
  }>;
79
- } & // | Renderable<{ // | string // header?: // accessorKey?: never // id: string // accessorFn: AccessorFn<TData> // | {
79
+ } & // instance: ReactTable< // | Renderable<{ // | string // header?: // accessorKey?: never // id: string // accessorFn: AccessorFn<TData> // | {
80
80
  {
81
81
  __generated: true;
82
82
  width?: number;
@@ -1,8 +1,9 @@
1
1
  import { OnChangeFn, ReactTable, Row, RowModel, Updater } from '../types';
2
+ export declare type PageCount = undefined | null | number;
2
3
  export declare type PaginationState = {
3
4
  pageIndex: number;
4
5
  pageSize: number;
5
- pageCount: number;
6
+ pageCount?: PageCount;
6
7
  };
7
8
  export declare type PaginationTableState = {
8
9
  pagination: PaginationState;
@@ -24,12 +25,12 @@ export declare type PaginationInstance<TData, TValue, TFilterFns, TSortingFns, T
24
25
  resetPageIndex: () => void;
25
26
  setPageSize: (updater: Updater<number>) => void;
26
27
  resetPageSize: () => void;
27
- setPageCount: (updater: Updater<number>) => void;
28
+ setPageCount: (updater: Updater<PageCount>) => void;
28
29
  getPageOptions: () => number[];
29
30
  getCanPreviousPage: () => boolean;
30
31
  getCanNextPage: () => boolean;
31
- gotoPreviousPage: () => void;
32
- gotoNextPage: () => void;
32
+ previousPage: () => void;
33
+ nextPage: () => void;
33
34
  getPaginationRowModel: () => RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>;
34
35
  getPrePaginationRows: () => Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[];
35
36
  getPrePaginationFlatRows: () => Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[];
@@ -4,4 +4,5 @@ export * from './utils/globalFilterRowsFn';
4
4
  export * from './utils/sortRowsFn';
5
5
  export * from './utils/groupRowsFn';
6
6
  export * from './utils/expandRowsFn';
7
+ export * from './utils/paginateRowsFn';
7
8
  export { createTable } from './createTable';
@@ -681,6 +681,32 @@
681
681
  };
682
682
  }
683
683
 
684
+ function paginateRowsFn(instance, rowModel) {
685
+ var _instance$getState$pa = instance.getState().pagination,
686
+ pageSize = _instance$getState$pa.pageSize,
687
+ pageIndex = _instance$getState$pa.pageIndex;
688
+ var rows = rowModel.rows,
689
+ flatRows = rowModel.flatRows,
690
+ rowsById = rowModel.rowsById;
691
+ var pageStart = pageSize * pageIndex;
692
+ var pageEnd = pageStart + pageSize;
693
+ rows = rows.slice(pageStart, pageEnd);
694
+
695
+ if (!instance.options.paginateExpandedRows) {
696
+ return expandRowsFn(instance, {
697
+ rows: rows,
698
+ flatRows: flatRows,
699
+ rowsById: rowsById
700
+ });
701
+ }
702
+
703
+ return {
704
+ rows: rows,
705
+ flatRows: flatRows,
706
+ rowsById: rowsById
707
+ };
708
+ }
709
+
684
710
  //
685
711
  function getInitialState$9() {
686
712
  return {
@@ -3477,8 +3503,7 @@
3477
3503
  return {
3478
3504
  pagination: {
3479
3505
  pageIndex: 0,
3480
- pageSize: 10,
3481
- pageCount: -1
3506
+ pageSize: 10
3482
3507
  }
3483
3508
  };
3484
3509
  }
@@ -3507,17 +3532,15 @@
3507
3532
  },
3508
3533
  setPagination: function setPagination(updater) {
3509
3534
  var safeUpdater = function safeUpdater(old) {
3510
- functionalUpdate(old, updater);
3535
+ var newState = functionalUpdate(updater, old);
3511
3536
 
3512
- if (!instance.options.paginateRowsFn) {
3513
- var _instance$getPreExpan;
3537
+ if (instance.options.paginateRowsFn) {
3538
+ var _instance$getPrePagin;
3514
3539
 
3515
- return _extends({}, old, {
3516
- pageCount: (_instance$getPreExpan = instance.getPreExpandedRows()) != null && _instance$getPreExpan.length ? Math.ceil(instance.getPreExpandedRows().length / instance.getState().pagination.pageSize) : 0
3517
- });
3540
+ newState.pageCount = (_instance$getPrePagin = instance.getPrePaginationRows()) != null && _instance$getPrePagin.length ? Math.ceil(instance.getPrePaginationRows().length / instance.getState().pagination.pageSize) : 0;
3518
3541
  }
3519
3542
 
3520
- return old;
3543
+ return newState;
3521
3544
  };
3522
3545
 
3523
3546
  return instance.options.onPaginationChange == null ? void 0 : instance.options.onPaginationChange(safeUpdater, functionalUpdate(safeUpdater, instance.getState().pagination));
@@ -3533,10 +3556,11 @@
3533
3556
  },
3534
3557
  setPageIndex: function setPageIndex(updater) {
3535
3558
  instance.setPagination(function (old) {
3536
- var newPageIndex = functionalUpdate(updater, old.pageIndex);
3537
- var maxPageIndex = old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
3559
+ var pageIndex = functionalUpdate(updater, old.pageIndex);
3560
+ var maxPageIndex = old.pageCount && old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
3561
+ pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
3538
3562
  return _extends({}, old, {
3539
- pageIndex: Math.min(Math.max(0, newPageIndex), maxPageIndex)
3563
+ pageIndex: pageIndex
3540
3564
  });
3541
3565
  });
3542
3566
  },
@@ -3561,8 +3585,14 @@
3561
3585
  },
3562
3586
  setPageCount: function setPageCount(updater) {
3563
3587
  return instance.setPagination(function (old) {
3588
+ var newPageCount = functionalUpdate(updater, old.pageCount);
3589
+
3590
+ if (typeof newPageCount === 'number') {
3591
+ newPageCount = Math.max(-1, newPageCount);
3592
+ }
3593
+
3564
3594
  return _extends({}, old, {
3565
- pageCount: Math.max(-1, functionalUpdate(updater, old.pageCount))
3595
+ pageCount: newPageCount
3566
3596
  });
3567
3597
  });
3568
3598
  },
@@ -3571,7 +3601,7 @@
3571
3601
  }, function (pageSize, pageCount) {
3572
3602
  var pageOptions = [];
3573
3603
 
3574
- if (pageCount > 0) {
3604
+ if (pageCount && pageCount > 0) {
3575
3605
  pageOptions = [].concat(new Array(pageCount)).fill(null).map(function (_, i) {
3576
3606
  return i;
3577
3607
  });
@@ -3601,13 +3631,13 @@
3601
3631
 
3602
3632
  return pageIndex < Math.ceil(instance.getPrePaginationRows().length / pageSize) - 1;
3603
3633
  },
3604
- gotoPreviousPage: function gotoPreviousPage() {
3605
- return instance.setPageIndex == null ? void 0 : instance.setPageIndex(function (old) {
3634
+ previousPage: function previousPage() {
3635
+ return instance.setPageIndex(function (old) {
3606
3636
  return old - 1;
3607
3637
  });
3608
3638
  },
3609
- gotoNextPage: function gotoNextPage() {
3610
- return instance.setPageIndex == null ? void 0 : instance.setPageIndex(function (old) {
3639
+ nextPage: function nextPage() {
3640
+ return instance.setPageIndex(function (old) {
3611
3641
  return old + 1;
3612
3642
  });
3613
3643
  },
@@ -4579,7 +4609,7 @@
4579
4609
  // The final calls start at the bottom of the model,
4580
4610
  // expanded rows, which then work their way up
4581
4611
  getRowModel: function getRowModel() {
4582
- return instance.getExpandedRowModel();
4612
+ return instance.getPaginationRowModel();
4583
4613
  },
4584
4614
  getRows: function getRows() {
4585
4615
  return instance.getRowModel().rows;
@@ -4766,6 +4796,7 @@
4766
4796
  exports.expandRowsFn = expandRowsFn;
4767
4797
  exports.globalFilterRowsFn = globalFilterRowsFn;
4768
4798
  exports.groupRowsFn = groupRowsFn;
4799
+ exports.paginateRowsFn = paginateRowsFn;
4769
4800
  exports.sortRowsFn = sortRowsFn;
4770
4801
 
4771
4802
  Object.defineProperty(exports, '__esModule', { value: true });