@tanstack/table-core 8.0.0-beta.7 → 8.0.0

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.0.0-beta.7",
4
+ "version": "8.0.0",
5
5
  "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/tanstack/table#readme",
@@ -11,7 +11,6 @@ import { functionalUpdate, makeStateUpdater, memo } from '../utils'
11
11
  export type PaginationState = {
12
12
  pageIndex: number
13
13
  pageSize: number
14
- pageCount?: number
15
14
  }
16
15
 
17
16
  export type PaginationTableState = {
@@ -23,6 +22,7 @@ export type PaginationInitialTableState = {
23
22
  }
24
23
 
25
24
  export type PaginationOptions<TGenerics extends TableGenerics> = {
25
+ pageCount?: number
26
26
  manualPagination?: boolean
27
27
  onPaginationChange?: OnChangeFn<PaginationState>
28
28
  autoResetPageIndex?: boolean
@@ -131,9 +131,9 @@ export const Pagination: TableFeature = {
131
131
  let pageIndex = functionalUpdate(updater, old.pageIndex)
132
132
 
133
133
  const maxPageIndex =
134
- typeof old.pageCount !== 'undefined'
135
- ? old.pageCount - 1
136
- : Number.MAX_SAFE_INTEGER
134
+ (typeof instance.options.pageCount === 'undefined' || instance.options.pageCount === -1) ?
135
+ Number.MAX_SAFE_INTEGER
136
+ : instance.options.pageCount - 1
137
137
 
138
138
  pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex)
139
139
 
@@ -172,7 +172,10 @@ export const Pagination: TableFeature = {
172
172
  },
173
173
  setPageCount: updater =>
174
174
  instance.setPagination(old => {
175
- let newPageCount = functionalUpdate(updater, old.pageCount ?? -1)
175
+ let newPageCount = functionalUpdate(
176
+ updater,
177
+ instance.options.pageCount ?? -1
178
+ )
176
179
 
177
180
  if (typeof newPageCount === 'number') {
178
181
  newPageCount = Math.max(-1, newPageCount)
@@ -185,11 +188,8 @@ export const Pagination: TableFeature = {
185
188
  }),
186
189
 
187
190
  getPageOptions: memo(
188
- () => [
189
- instance.getState().pagination.pageSize,
190
- instance.getState().pagination.pageCount,
191
- ],
192
- (pageSize, pageCount) => {
191
+ () => [instance.getPageCount()],
192
+ pageCount => {
193
193
  let pageOptions: number[] = []
194
194
  if (pageCount && pageCount > 0) {
195
195
  pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i)
@@ -251,15 +251,12 @@ export const Pagination: TableFeature = {
251
251
  },
252
252
 
253
253
  getPageCount: () => {
254
- const { pageCount } = instance.getState().pagination
255
-
256
- if (typeof pageCount !== 'undefined') {
257
- return pageCount
258
- }
259
-
260
- return Math.ceil(
261
- instance.getPrePaginationRowModel().rows.length /
254
+ return (
255
+ instance.options.pageCount ??
256
+ Math.ceil(
257
+ instance.getPrePaginationRowModel().rows.length /
262
258
  instance.getState().pagination.pageSize
259
+ )
263
260
  )
264
261
  },
265
262
  }
package/src/filterFns.ts CHANGED
@@ -6,7 +6,7 @@ const includesString: FilterFn<any> = (
6
6
  filterValue: string
7
7
  ) => {
8
8
  const search = filterValue.toLowerCase()
9
- return row.getValue(columnId).toLowerCase().includes(search)
9
+ return row.getValue(columnId)?.toLowerCase().includes(search)
10
10
  }
11
11
 
12
12
  includesString.autoRemove = (val: any) => testFalsey(val)
@@ -16,7 +16,7 @@ const includesStringSensitive: FilterFn<any> = (
16
16
  columnId: string,
17
17
  filterValue: string
18
18
  ) => {
19
- return row.getValue(columnId).includes(filterValue)
19
+ return row.getValue(columnId)?.includes(filterValue)
20
20
  }
21
21
 
22
22
  includesStringSensitive.autoRemove = (val: any) => testFalsey(val)
@@ -26,7 +26,7 @@ const equalsString: FilterFn<any> = (
26
26
  columnId: string,
27
27
  filterValue: string
28
28
  ) => {
29
- return row.getValue(columnId).toLowerCase() === filterValue.toLowerCase()
29
+ return row.getValue(columnId)?.toLowerCase() === filterValue.toLowerCase()
30
30
  }
31
31
 
32
32
  equalsString.autoRemove = (val: any) => testFalsey(val)
@@ -36,7 +36,7 @@ const arrIncludes: FilterFn<any> = (
36
36
  columnId: string,
37
37
  filterValue: unknown
38
38
  ) => {
39
- return row.getValue(columnId).includes(filterValue)
39
+ return row.getValue(columnId)?.includes(filterValue)
40
40
  }
41
41
 
42
42
  arrIncludes.autoRemove = (val: any) => testFalsey(val) || !val?.length
@@ -46,7 +46,7 @@ const arrIncludesAll: FilterFn<any> = (
46
46
  columnId: string,
47
47
  filterValue: unknown[]
48
48
  ) => {
49
- return !filterValue.some(val => !row.getValue(columnId).includes(val))
49
+ return !filterValue.some(val => !row.getValue(columnId)?.includes(val))
50
50
  }
51
51
 
52
52
  arrIncludesAll.autoRemove = (val: any) => testFalsey(val) || !val?.length
@@ -56,7 +56,7 @@ const arrIncludesSome: FilterFn<any> = (
56
56
  columnId: string,
57
57
  filterValue: unknown[]
58
58
  ) => {
59
- return filterValue.some(val => row.getValue(columnId).includes(val))
59
+ return filterValue.some(val => row.getValue(columnId)?.includes(val))
60
60
  }
61
61
 
62
62
  arrIncludesSome.autoRemove = (val: any) => testFalsey(val) || !val?.length
@@ -21,18 +21,16 @@ export function filterRowModelFromLeafs<TGenerics extends TableGenerics>(
21
21
  const newFilteredFlatRows: Row<TGenerics>[] = []
22
22
  const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
23
23
 
24
- let row
25
- let newRow
26
24
 
27
25
  const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
28
26
  const rows: Row<TGenerics>[] = []
29
27
 
30
28
  // Filter from children up first
31
29
  for (let i = 0; i < rowsToFilter.length; i++) {
32
- row = rowsToFilter[i]!
30
+ let row = rowsToFilter[i]!
33
31
 
34
32
  if (row.subRows?.length) {
35
- newRow = createRow(instance, row.id, row.original, row.index, row.depth)
33
+ const newRow = createRow(instance, row.id, row.original, row.index, row.depth)
36
34
  newRow.columnFilters = row.columnFilters
37
35
  newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
38
36
  if (!newRow.subRows.length) {
@@ -66,25 +64,21 @@ export function filterRowModelFromRoot<TGenerics extends TableGenerics>(
66
64
  const newFilteredFlatRows: Row<TGenerics>[] = []
67
65
  const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
68
66
 
69
- let rows
70
- let row
71
- let newRow
72
-
73
67
  // Filters top level and nested rows
74
68
  const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
75
69
  // Filter from parents downward first
76
70
 
77
- rows = []
71
+ const rows = []
78
72
 
79
73
  // Apply the filter to any subRows
80
74
  for (let i = 0; i < rowsToFilter.length; i++) {
81
- row = rowsToFilter[i]!
75
+ let row = rowsToFilter[i]!
82
76
 
83
77
  const pass = filterRow(row)
84
78
 
85
79
  if (pass) {
86
80
  if (row.subRows?.length) {
87
- newRow = createRow(
81
+ const newRow = createRow(
88
82
  instance,
89
83
  row.id,
90
84
  row.original,