@tanstack/table-core 8.9.2 → 8.9.3

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.9.2",
4
+ "version": "8.9.3",
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",
@@ -116,6 +116,7 @@ export const Sorting: TableFeature = {
116
116
  getDefaultColumnDef: <TData extends RowData>(): SortingColumnDef<TData> => {
117
117
  return {
118
118
  sortingFn: 'auto',
119
+ sortUndefined: 1,
119
120
  }
120
121
  },
121
122
 
@@ -53,32 +53,31 @@ export function getSortedRowModel<TData extends RowData>(): (
53
53
  const columnInfo = columnInfoById[sortEntry.id]!
54
54
  const isDesc = sortEntry?.desc ?? false
55
55
 
56
+ let sortInt = 0
57
+
58
+ // All sorting ints should always return in ascending order
56
59
  if (columnInfo.sortUndefined) {
57
60
  const aValue = rowA.getValue(sortEntry.id)
58
61
  const bValue = rowB.getValue(sortEntry.id)
59
62
 
60
- const aUndefined = typeof aValue === 'undefined'
61
- const bUndefined = typeof bValue === 'undefined'
63
+ const aUndefined = aValue === undefined
64
+ const bUndefined = bValue === undefined
62
65
 
63
66
  if (aUndefined || bUndefined) {
64
- let undefinedSort =
67
+ sortInt =
65
68
  aUndefined && bUndefined
66
69
  ? 0
67
70
  : aUndefined
68
71
  ? columnInfo.sortUndefined
69
72
  : -columnInfo.sortUndefined
70
-
71
- if (isDesc && undefinedSort !== 0) {
72
- undefinedSort *= -1
73
- }
74
-
75
- return undefinedSort
76
73
  }
77
74
  }
78
75
 
79
- // This function should always return in ascending order
80
- let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)
76
+ if (sortInt === 0) {
77
+ sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)
78
+ }
81
79
 
80
+ // If sorting is non-zero, take care of desc and inversion
82
81
  if (sortInt !== 0) {
83
82
  if (isDesc) {
84
83
  sortInt *= -1