@tanstack/table-core 8.12.0 → 8.13.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
- "version": "8.12.0",
3
+ "version": "8.13.1",
4
4
  "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -48,11 +48,17 @@ export interface PaginationOptions {
48
48
  */
49
49
  onPaginationChange?: OnChangeFn<PaginationState>
50
50
  /**
51
- * When manually controlling pagination, you should supply a total `pageCount` value to the table if you know it. If you do not know how many pages there are, you can set this to `-1`.
51
+ * When manually controlling pagination, you can supply a total `pageCount` value to the table if you know it (Or supply a `rowCount` and `pageCount` will be calculated). If you do not know how many pages there are, you can set this to `-1`.
52
52
  * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#pagecount)
53
53
  * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)
54
54
  */
55
55
  pageCount?: number
56
+ /**
57
+ * When manually controlling pagination, you can supply a total `rowCount` value to the table if you know it. The `pageCount` can be calculated from this value and the `pageSize`.
58
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#rowcount)
59
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)
60
+ */
61
+ rowCount?: number
56
62
  }
57
63
 
58
64
  export interface PaginationDefaultOptions {
@@ -80,6 +86,12 @@ export interface PaginationInstance<TData extends RowData> {
80
86
  * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)
81
87
  */
82
88
  getPageCount: () => number
89
+ /**
90
+ * Returns the row count. If manually paginating or controlling the pagination state, this will come directly from the `options.rowCount` table option, otherwise it will be calculated from the table data.
91
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getrowcount)
92
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)
93
+ */
94
+ getRowCount: () => number
83
95
  /**
84
96
  * Returns an array of page options (zero-index-based) for the current page size.
85
97
  * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getpageoptions)
@@ -110,6 +122,18 @@ export interface PaginationInstance<TData extends RowData> {
110
122
  * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)
111
123
  */
112
124
  previousPage: () => void
125
+ /**
126
+ * Sets the page index to `0`.
127
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#firstpage)
128
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)
129
+ */
130
+ firstPage: () => void
131
+ /**
132
+ * Sets the page index to the last page.
133
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#lastpage)
134
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)
135
+ */
136
+ lastPage: () => void
113
137
  /**
114
138
  * Resets the page index to its initial state. If `defaultState` is `true`, the page index will be reset to `0` regardless of initial state.
115
139
  * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#resetpageindex)
@@ -129,9 +153,7 @@ export interface PaginationInstance<TData extends RowData> {
129
153
  */
130
154
  resetPagination: (defaultState?: boolean) => void
131
155
  /**
132
- * Updates the page count using the provided function or value.
133
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#setpagecount)
134
- * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)
156
+ * @deprecated The page count no longer exists in the pagination state. Just pass as a table option instead.
135
157
  */
136
158
  setPageCount: (updater: Updater<number>) => void
137
159
  /**
@@ -269,6 +291,7 @@ export const Pagination: TableFeature = {
269
291
  }
270
292
  })
271
293
  }
294
+ //deprecated
272
295
  table.setPageCount = updater =>
273
296
  table.setPagination(old => {
274
297
  let newPageCount = functionalUpdate(
@@ -326,6 +349,14 @@ export const Pagination: TableFeature = {
326
349
  })
327
350
  }
328
351
 
352
+ table.firstPage = () => {
353
+ return table.setPageIndex(0)
354
+ }
355
+
356
+ table.lastPage = () => {
357
+ return table.setPageIndex(table.getPageCount() - 1)
358
+ }
359
+
329
360
  table.getPrePaginationRowModel = () => table.getExpandedRowModel()
330
361
  table.getPaginationRowModel = () => {
331
362
  if (
@@ -346,10 +377,13 @@ export const Pagination: TableFeature = {
346
377
  table.getPageCount = () => {
347
378
  return (
348
379
  table.options.pageCount ??
349
- Math.ceil(
350
- table.getPrePaginationRowModel().rows.length /
351
- table.getState().pagination.pageSize
352
- )
380
+ Math.ceil(table.getRowCount() / table.getState().pagination.pageSize)
381
+ )
382
+ }
383
+
384
+ table.getRowCount = () => {
385
+ return (
386
+ table.options.rowCount ?? table.getPrePaginationRowModel().rows.length
353
387
  )
354
388
  }
355
389
  },
@@ -429,7 +429,7 @@ export const Pinning: TableFeature = {
429
429
  getMemoOptions(table.options, 'debugRows', 'getCenterVisibleCells')
430
430
  )
431
431
  row.getLeftVisibleCells = memo(
432
- () => [row._getAllVisibleCells(), table.getState().columnPinning.left, ,],
432
+ () => [row._getAllVisibleCells(), table.getState().columnPinning.left],
433
433
  (allCells, left) => {
434
434
  const cells = (left ?? [])
435
435
  .map(columnId => allCells.find(cell => cell.column.id === columnId)!)
@@ -18,6 +18,11 @@ export interface VisibilityTableState {
18
18
  }
19
19
 
20
20
  export interface VisibilityOptions {
21
+ /**
22
+ * Whether to enable column hiding. Defaults to `true`.
23
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-visibility#enablehiding)
24
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-visibility)
25
+ */
21
26
  enableHiding?: boolean
22
27
  /**
23
28
  * If provided, this function will be called with an `updaterFn` when `state.columnVisibility` changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
@@ -173,7 +178,12 @@ export const Visibility: TableFeature = {
173
178
  }
174
179
  }
175
180
  column.getIsVisible = () => {
176
- return table.getState().columnVisibility?.[column.id] ?? true
181
+ const childColumns = column.columns
182
+ return (
183
+ (childColumns.length
184
+ ? childColumns.some(c => c.getIsVisible())
185
+ : table.getState().columnVisibility?.[column.id]) ?? true
186
+ )
177
187
  }
178
188
 
179
189
  column.getCanHide = () => {
@@ -13,7 +13,7 @@ export function filterRows<TData extends RowData>(
13
13
  return filterRowModelFromRoot(rows, filterRowImpl, table)
14
14
  }
15
15
 
16
- export function filterRowModelFromLeafs<TData extends RowData>(
16
+ function filterRowModelFromLeafs<TData extends RowData>(
17
17
  rowsToFilter: Row<TData>[],
18
18
  filterRow: (row: Row<TData>) => Row<TData>[],
19
19
  table: Table<TData>
@@ -77,7 +77,7 @@ export function filterRowModelFromLeafs<TData extends RowData>(
77
77
  }
78
78
  }
79
79
 
80
- export function filterRowModelFromRoot<TData extends RowData>(
80
+ function filterRowModelFromRoot<TData extends RowData>(
81
81
  rowsToFilter: Row<TData>[],
82
82
  filterRow: (row: Row<TData>) => any,
83
83
  table: Table<TData>