@tanstack/table-core 8.15.2 → 8.16.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
- "version": "8.15.2",
3
+ "version": "8.16.0",
4
4
  "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -283,11 +283,9 @@ export const ColumnGrouping: TableFeature = {
283
283
 
284
284
  column.getCanGroup = () => {
285
285
  return (
286
- column.columnDef.enableGrouping ??
287
- true ??
288
- table.options.enableGrouping ??
289
- true ??
290
- !!column.accessorFn
286
+ (column.columnDef.enableGrouping ?? true) &&
287
+ (table.options.enableGrouping ?? true) &&
288
+ (!!column.accessorFn || !!column.columnDef.getGroupingValue)
291
289
  )
292
290
  }
293
291
 
@@ -90,7 +90,7 @@ export interface SortingColumnDef<TData extends RowData> {
90
90
  * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortundefined)
91
91
  * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
92
92
  */
93
- sortUndefined?: false | -1 | 1
93
+ sortUndefined?: false | -1 | 1 | 'first' | 'last'
94
94
  }
95
95
 
96
96
  export interface SortingColumn<TData extends RowData> {
@@ -25,7 +25,7 @@ export function getSortedRowModel<TData extends RowData>(): (
25
25
  const columnInfoById: Record<
26
26
  string,
27
27
  {
28
- sortUndefined?: false | -1 | 1
28
+ sortUndefined?: false | -1 | 1 | 'first' | 'last'
29
29
  invertSorting?: boolean
30
30
  sortingFn: SortingFn<TData>
31
31
  }
@@ -51,12 +51,13 @@ export function getSortedRowModel<TData extends RowData>(): (
51
51
  for (let i = 0; i < availableSorting.length; i += 1) {
52
52
  const sortEntry = availableSorting[i]!
53
53
  const columnInfo = columnInfoById[sortEntry.id]!
54
+ const sortUndefined = columnInfo.sortUndefined
54
55
  const isDesc = sortEntry?.desc ?? false
55
56
 
56
57
  let sortInt = 0
57
58
 
58
59
  // All sorting ints should always return in ascending order
59
- if (columnInfo.sortUndefined) {
60
+ if (sortUndefined) {
60
61
  const aValue = rowA.getValue(sortEntry.id)
61
62
  const bValue = rowB.getValue(sortEntry.id)
62
63
 
@@ -64,12 +65,14 @@ export function getSortedRowModel<TData extends RowData>(): (
64
65
  const bUndefined = bValue === undefined
65
66
 
66
67
  if (aUndefined || bUndefined) {
68
+ if (sortUndefined === 'first') return aUndefined ? -1 : 1
69
+ if (sortUndefined === 'last') return aUndefined ? 1 : -1
67
70
  sortInt =
68
71
  aUndefined && bUndefined
69
72
  ? 0
70
73
  : aUndefined
71
- ? columnInfo.sortUndefined
72
- : -columnInfo.sortUndefined
74
+ ? sortUndefined
75
+ : -sortUndefined
73
76
  }
74
77
  }
75
78