@tanstack/table-core 8.2.1 → 8.2.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/features/RowSelection.js +9 -3
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +33 -26
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/sortingFns.js +6 -1
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +14 -3
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/esm/index.js +62 -33
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +307 -307
- package/build/types/index.d.ts +1 -0
- package/build/umd/index.development.js +62 -33
- 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/features/RowSelection.ts +7 -2
- package/src/features/Sorting.ts +38 -27
- package/src/sortingFns.ts +7 -4
- package/src/utils/getGroupedRowModel.ts +16 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.2.
|
|
4
|
+
"version": "8.2.4",
|
|
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",
|
|
@@ -108,6 +108,9 @@ export const RowSelection: TableFeature = {
|
|
|
108
108
|
// All of the rows are flat already, so it wouldn't be worth it
|
|
109
109
|
if (value) {
|
|
110
110
|
preGroupedFlatRows.forEach(row => {
|
|
111
|
+
if (!row.getCanSelect()) {
|
|
112
|
+
return
|
|
113
|
+
}
|
|
111
114
|
rowSelection[row.id] = true
|
|
112
115
|
})
|
|
113
116
|
} else {
|
|
@@ -420,7 +423,7 @@ const mutateRowIsSelected = <TData extends RowData>(
|
|
|
420
423
|
) => {
|
|
421
424
|
const row = table.getRow(id)
|
|
422
425
|
|
|
423
|
-
const isGrouped = row.getIsGrouped()
|
|
426
|
+
// const isGrouped = row.getIsGrouped()
|
|
424
427
|
|
|
425
428
|
// if ( // TODO: enforce grouping row selection rules
|
|
426
429
|
// !isGrouped ||
|
|
@@ -430,7 +433,9 @@ const mutateRowIsSelected = <TData extends RowData>(
|
|
|
430
433
|
if (!row.getCanMultiSelect()) {
|
|
431
434
|
Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key])
|
|
432
435
|
}
|
|
433
|
-
|
|
436
|
+
if (row.getCanSelect()) {
|
|
437
|
+
selectedRowIds[id] = true
|
|
438
|
+
}
|
|
434
439
|
} else {
|
|
435
440
|
delete selectedRowIds[id]
|
|
436
441
|
}
|
package/src/features/Sorting.ts
CHANGED
|
@@ -58,6 +58,7 @@ export type SortingColumn<TData extends RowData> = {
|
|
|
58
58
|
getAutoSortingFn: () => SortingFn<TData>
|
|
59
59
|
getAutoSortDir: () => SortDirection
|
|
60
60
|
getSortingFn: () => SortingFn<TData>
|
|
61
|
+
getFirstSortDir: () => SortDirection
|
|
61
62
|
getNextSortingOrder: () => SortDirection | false
|
|
62
63
|
getCanSort: () => boolean
|
|
63
64
|
getCanMultiSort: () => boolean
|
|
@@ -184,19 +185,21 @@ export const Sorting: TableFeature = {
|
|
|
184
185
|
|
|
185
186
|
// this needs to be outside of table.setSorting to be in sync with rerender
|
|
186
187
|
const nextSortingOrder = column.getNextSortingOrder()
|
|
188
|
+
const hasManualValue = typeof desc !== 'undefined' && desc !== null
|
|
187
189
|
|
|
188
190
|
table.setSorting(old => {
|
|
189
191
|
// Find any existing sorting for this column
|
|
190
192
|
const existingSorting = old?.find(d => d.id === column.id)
|
|
191
193
|
const existingIndex = old?.findIndex(d => d.id === column.id)
|
|
192
|
-
const hasDescDefined = typeof desc !== 'undefined' && desc !== null
|
|
193
194
|
|
|
194
195
|
let newSorting: SortingState = []
|
|
195
196
|
|
|
196
197
|
// What should we do with this sort action?
|
|
197
198
|
let sortAction: 'add' | 'remove' | 'toggle' | 'replace'
|
|
199
|
+
let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'
|
|
198
200
|
|
|
199
|
-
|
|
201
|
+
// Multi-mode
|
|
202
|
+
if (old?.length && column.getCanMultiSort() && multi) {
|
|
200
203
|
if (existingSorting) {
|
|
201
204
|
sortAction = 'toggle'
|
|
202
205
|
} else {
|
|
@@ -214,29 +217,22 @@ export const Sorting: TableFeature = {
|
|
|
214
217
|
}
|
|
215
218
|
|
|
216
219
|
// Handle toggle states that will remove the sorting
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
220
|
+
if (sortAction === 'toggle') {
|
|
221
|
+
// If we are "actually" toggling (not a manual set value), should we remove the sorting?
|
|
222
|
+
if (!hasManualValue) {
|
|
223
|
+
// Is our intention to remove?
|
|
224
|
+
if (!nextSortingOrder) {
|
|
225
|
+
sortAction = 'remove'
|
|
226
|
+
}
|
|
227
|
+
}
|
|
225
228
|
}
|
|
226
229
|
|
|
227
|
-
if (sortAction === '
|
|
228
|
-
newSorting = [
|
|
229
|
-
{
|
|
230
|
-
id: column.id,
|
|
231
|
-
desc: hasDescDefined ? desc! : nextSortingOrder! === 'desc',
|
|
232
|
-
},
|
|
233
|
-
]
|
|
234
|
-
} else if (sortAction === 'add' && old?.length) {
|
|
230
|
+
if (sortAction === 'add') {
|
|
235
231
|
newSorting = [
|
|
236
232
|
...old,
|
|
237
233
|
{
|
|
238
234
|
id: column.id,
|
|
239
|
-
desc:
|
|
235
|
+
desc: nextDesc,
|
|
240
236
|
},
|
|
241
237
|
]
|
|
242
238
|
// Take latest n columns
|
|
@@ -245,41 +241,56 @@ export const Sorting: TableFeature = {
|
|
|
245
241
|
newSorting.length -
|
|
246
242
|
(table.options.maxMultiSortColCount ?? Number.MAX_SAFE_INTEGER)
|
|
247
243
|
)
|
|
248
|
-
} else if (sortAction === 'toggle'
|
|
244
|
+
} else if (sortAction === 'toggle') {
|
|
249
245
|
// This flips (or sets) the
|
|
250
246
|
newSorting = old.map(d => {
|
|
251
247
|
if (d.id === column.id) {
|
|
252
248
|
return {
|
|
253
249
|
...d,
|
|
254
|
-
desc:
|
|
250
|
+
desc: nextDesc,
|
|
255
251
|
}
|
|
256
252
|
}
|
|
257
253
|
return d
|
|
258
254
|
})
|
|
259
|
-
} else if (sortAction === 'remove'
|
|
255
|
+
} else if (sortAction === 'remove') {
|
|
260
256
|
newSorting = old.filter(d => d.id !== column.id)
|
|
257
|
+
} else {
|
|
258
|
+
newSorting = [
|
|
259
|
+
{
|
|
260
|
+
id: column.id,
|
|
261
|
+
desc: nextDesc,
|
|
262
|
+
},
|
|
263
|
+
]
|
|
261
264
|
}
|
|
262
265
|
|
|
263
266
|
return newSorting
|
|
264
267
|
})
|
|
265
268
|
},
|
|
266
269
|
|
|
267
|
-
|
|
270
|
+
getFirstSortDir: () => {
|
|
268
271
|
const sortDescFirst =
|
|
269
272
|
column.columnDef.sortDescFirst ??
|
|
270
273
|
table.options.sortDescFirst ??
|
|
271
274
|
column.getAutoSortDir() === 'desc'
|
|
272
|
-
|
|
275
|
+
return sortDescFirst ? 'desc' : 'asc'
|
|
276
|
+
},
|
|
273
277
|
|
|
278
|
+
getNextSortingOrder: (multi?: boolean) => {
|
|
279
|
+
const firstSortDirection = column.getFirstSortDir()
|
|
274
280
|
const isSorted = column.getIsSorted()
|
|
281
|
+
|
|
275
282
|
if (!isSorted) {
|
|
276
283
|
return firstSortDirection
|
|
277
284
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
285
|
+
|
|
286
|
+
if (
|
|
287
|
+
isSorted !== firstSortDirection &&
|
|
288
|
+
(table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general
|
|
289
|
+
(multi ? table.options.enableMultiRemove ?? true : true) // If multi, don't allow if enableMultiRemove))
|
|
290
|
+
) {
|
|
281
291
|
return false
|
|
282
292
|
}
|
|
293
|
+
return isSorted === 'desc' ? 'asc' : 'desc'
|
|
283
294
|
},
|
|
284
295
|
|
|
285
296
|
getCanSort: () => {
|
package/src/sortingFns.ts
CHANGED
|
@@ -35,10 +35,13 @@ const textCaseSensitive: SortingFn<any> = (rowA, rowB, columnId) => {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const datetime: SortingFn<any> = (rowA, rowB, columnId) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const a = rowA.getValue<Date>(columnId)
|
|
39
|
+
const b = rowB.getValue<Date>(columnId)
|
|
40
|
+
|
|
41
|
+
// Can handle nullish values
|
|
42
|
+
// Use > and < because == (and ===) doesn't work with
|
|
43
|
+
// Date objects (would require calling getTime()).
|
|
44
|
+
return a > b ? 1 : a < b ? -1 : 0
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
const basic: SortingFn<any> = (rowA, rowB, columnId) => {
|
|
@@ -29,11 +29,23 @@ export function getGroupedRowModel<TData extends RowData>(): (
|
|
|
29
29
|
const groupUpRecursively = (
|
|
30
30
|
rows: Row<TData>[],
|
|
31
31
|
depth = 0,
|
|
32
|
-
parentId
|
|
32
|
+
parentId?: string
|
|
33
33
|
) => {
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
// Grouping depth has been been met
|
|
35
|
+
// Stop grouping and simply rewrite thd depth and row relationships
|
|
36
|
+
if (depth >= existingGrouping.length) {
|
|
37
|
+
return rows.map(row => {
|
|
38
|
+
row.depth = depth
|
|
39
|
+
|
|
40
|
+
groupedFlatRows.push(row)
|
|
41
|
+
groupedRowsById[row.id] = row
|
|
42
|
+
|
|
43
|
+
if (row.subRows) {
|
|
44
|
+
row.subRows = groupUpRecursively(row.subRows, depth + 1)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return row
|
|
48
|
+
})
|
|
37
49
|
}
|
|
38
50
|
|
|
39
51
|
const columnId = existingGrouping[depth]!
|