@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/build/lib/features/Sorting.js +2 -1
- package/build/lib/features/Sorting.js.map +1 -1
- package/build/lib/index.esm.js +12 -10
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.mjs +12 -10
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/utils/getSortedRowModel.js +10 -9
- package/build/lib/utils/getSortedRowModel.js.map +1 -1
- package/build/umd/index.development.js +12 -10
- 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/Sorting.ts +1 -0
- package/src/utils/getSortedRowModel.ts +10 -11
|
@@ -47,22 +47,23 @@ function getSortedRowModel() {
|
|
|
47
47
|
const sortEntry = availableSorting[i];
|
|
48
48
|
const columnInfo = columnInfoById[sortEntry.id];
|
|
49
49
|
const isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
|
|
50
|
+
let sortInt = 0;
|
|
51
|
+
|
|
52
|
+
// All sorting ints should always return in ascending order
|
|
50
53
|
if (columnInfo.sortUndefined) {
|
|
51
54
|
const aValue = rowA.getValue(sortEntry.id);
|
|
52
55
|
const bValue = rowB.getValue(sortEntry.id);
|
|
53
|
-
const aUndefined =
|
|
54
|
-
const bUndefined =
|
|
56
|
+
const aUndefined = aValue === undefined;
|
|
57
|
+
const bUndefined = bValue === undefined;
|
|
55
58
|
if (aUndefined || bUndefined) {
|
|
56
|
-
|
|
57
|
-
if (isDesc && undefinedSort !== 0) {
|
|
58
|
-
undefinedSort *= -1;
|
|
59
|
-
}
|
|
60
|
-
return undefinedSort;
|
|
59
|
+
sortInt = aUndefined && bUndefined ? 0 : aUndefined ? columnInfo.sortUndefined : -columnInfo.sortUndefined;
|
|
61
60
|
}
|
|
62
61
|
}
|
|
62
|
+
if (sortInt === 0) {
|
|
63
|
+
sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
|
|
64
|
+
}
|
|
63
65
|
|
|
64
|
-
//
|
|
65
|
-
let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
|
|
66
|
+
// If sorting is non-zero, take care of desc and inversion
|
|
66
67
|
if (sortInt !== 0) {
|
|
67
68
|
if (isDesc) {
|
|
68
69
|
sortInt *= -1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSortedRowModel.js","sources":["../../../src/utils/getSortedRowModel.ts"],"sourcesContent":["import { Table, Row, RowModel, RowData } from '../types'\nimport { SortingFn } from '../features/Sorting'\nimport { memo } from '../utils'\n\nexport function getSortedRowModel<TData extends RowData>(): (\n table: Table<TData>\n) => () => RowModel<TData> {\n return table =>\n memo(\n () => [table.getState().sorting, table.getPreSortedRowModel()],\n (sorting, rowModel) => {\n if (!rowModel.rows.length || !sorting?.length) {\n return rowModel\n }\n\n const sortingState = table.getState().sorting\n\n const sortedFlatRows: Row<TData>[] = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sortingState.filter(sort =>\n table.getColumn(sort.id)?.getCanSort()\n )\n\n const columnInfoById: Record<\n string,\n {\n sortUndefined?: false | -1 | 1\n invertSorting?: boolean\n sortingFn: SortingFn<TData>\n }\n > = {}\n\n availableSorting.forEach(sortEntry => {\n const column = table.getColumn(sortEntry.id)\n if (!column) return\n\n columnInfoById[sortEntry.id] = {\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortingFn: column.getSortingFn(),\n }\n })\n\n const sortData = (rows: Row<TData>[]) => {\n // This will also perform a stable sorting using the row index\n // if needed.\n const sortedData = [...rows]\n\n sortedData.sort((rowA, rowB) => {\n for (let i = 0; i < availableSorting.length; i += 1) {\n const sortEntry = availableSorting[i]!\n const columnInfo = columnInfoById[sortEntry.id]!\n const isDesc = sortEntry?.desc ?? false\n\n if (columnInfo.sortUndefined) {\n const aValue = rowA.getValue(sortEntry.id)\n const bValue = rowB.getValue(sortEntry.id)\n\n const aUndefined =
|
|
1
|
+
{"version":3,"file":"getSortedRowModel.js","sources":["../../../src/utils/getSortedRowModel.ts"],"sourcesContent":["import { Table, Row, RowModel, RowData } from '../types'\nimport { SortingFn } from '../features/Sorting'\nimport { memo } from '../utils'\n\nexport function getSortedRowModel<TData extends RowData>(): (\n table: Table<TData>\n) => () => RowModel<TData> {\n return table =>\n memo(\n () => [table.getState().sorting, table.getPreSortedRowModel()],\n (sorting, rowModel) => {\n if (!rowModel.rows.length || !sorting?.length) {\n return rowModel\n }\n\n const sortingState = table.getState().sorting\n\n const sortedFlatRows: Row<TData>[] = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sortingState.filter(sort =>\n table.getColumn(sort.id)?.getCanSort()\n )\n\n const columnInfoById: Record<\n string,\n {\n sortUndefined?: false | -1 | 1\n invertSorting?: boolean\n sortingFn: SortingFn<TData>\n }\n > = {}\n\n availableSorting.forEach(sortEntry => {\n const column = table.getColumn(sortEntry.id)\n if (!column) return\n\n columnInfoById[sortEntry.id] = {\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortingFn: column.getSortingFn(),\n }\n })\n\n const sortData = (rows: Row<TData>[]) => {\n // This will also perform a stable sorting using the row index\n // if needed.\n const sortedData = [...rows]\n\n sortedData.sort((rowA, rowB) => {\n for (let i = 0; i < availableSorting.length; i += 1) {\n const sortEntry = availableSorting[i]!\n const columnInfo = columnInfoById[sortEntry.id]!\n const isDesc = sortEntry?.desc ?? false\n\n let sortInt = 0\n\n // All sorting ints should always return in ascending order\n if (columnInfo.sortUndefined) {\n const aValue = rowA.getValue(sortEntry.id)\n const bValue = rowB.getValue(sortEntry.id)\n\n const aUndefined = aValue === undefined\n const bUndefined = bValue === undefined\n\n if (aUndefined || bUndefined) {\n sortInt =\n aUndefined && bUndefined\n ? 0\n : aUndefined\n ? columnInfo.sortUndefined\n : -columnInfo.sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)\n }\n\n // If sorting is non-zero, take care of desc and inversion\n if (sortInt !== 0) {\n if (isDesc) {\n sortInt *= -1\n }\n\n if (columnInfo.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n })\n\n // If there are sub-rows, sort them\n sortedData.forEach(row => {\n sortedFlatRows.push(row)\n if (row.subRows?.length) {\n row.subRows = sortData(row.subRows)\n }\n })\n\n return sortedData\n }\n\n return {\n rows: sortData(rowModel.rows),\n flatRows: sortedFlatRows,\n rowsById: rowModel.rowsById,\n }\n },\n {\n key: process.env.NODE_ENV === 'development' && 'getSortedRowModel',\n debug: () => table.options.debugAll ?? table.options.debugTable,\n onChange: () => {\n table._autoResetPageIndex()\n },\n }\n )\n}\n"],"names":["getSortedRowModel","table","memo","getState","sorting","getPreSortedRowModel","rowModel","rows","length","sortingState","sortedFlatRows","availableSorting","filter","sort","_table$getColumn","getColumn","id","getCanSort","columnInfoById","forEach","sortEntry","column","sortUndefined","columnDef","invertSorting","sortingFn","getSortingFn","sortData","sortedData","rowA","rowB","i","_sortEntry$desc","columnInfo","isDesc","desc","sortInt","aValue","getValue","bValue","aUndefined","undefined","bUndefined","index","row","_row$subRows","push","subRows","flatRows","rowsById","key","process","env","NODE_ENV","debug","_table$options$debugA","options","debugAll","debugTable","onChange","_autoResetPageIndex"],"mappings":";;;;;;;;;;;;;;;;AAIO,SAASA,iBAAiBA,GAEN;EACzB,OAAOC,KAAK,IACVC,UAAI,CACF,MAAM,CAACD,KAAK,CAACE,QAAQ,EAAE,CAACC,OAAO,EAAEH,KAAK,CAACI,oBAAoB,EAAE,CAAC,EAC9D,CAACD,OAAO,EAAEE,QAAQ,KAAK;AACrB,IAAA,IAAI,CAACA,QAAQ,CAACC,IAAI,CAACC,MAAM,IAAI,EAACJ,OAAO,IAAA,IAAA,IAAPA,OAAO,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
|
@@ -2310,7 +2310,8 @@
|
|
|
2310
2310
|
},
|
|
2311
2311
|
getDefaultColumnDef: () => {
|
|
2312
2312
|
return {
|
|
2313
|
-
sortingFn: 'auto'
|
|
2313
|
+
sortingFn: 'auto',
|
|
2314
|
+
sortUndefined: 1
|
|
2314
2315
|
};
|
|
2315
2316
|
},
|
|
2316
2317
|
getDefaultOptions: table => {
|
|
@@ -3357,22 +3358,23 @@
|
|
|
3357
3358
|
const sortEntry = availableSorting[i];
|
|
3358
3359
|
const columnInfo = columnInfoById[sortEntry.id];
|
|
3359
3360
|
const isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
|
|
3361
|
+
let sortInt = 0;
|
|
3362
|
+
|
|
3363
|
+
// All sorting ints should always return in ascending order
|
|
3360
3364
|
if (columnInfo.sortUndefined) {
|
|
3361
3365
|
const aValue = rowA.getValue(sortEntry.id);
|
|
3362
3366
|
const bValue = rowB.getValue(sortEntry.id);
|
|
3363
|
-
const aUndefined =
|
|
3364
|
-
const bUndefined =
|
|
3367
|
+
const aUndefined = aValue === undefined;
|
|
3368
|
+
const bUndefined = bValue === undefined;
|
|
3365
3369
|
if (aUndefined || bUndefined) {
|
|
3366
|
-
|
|
3367
|
-
if (isDesc && undefinedSort !== 0) {
|
|
3368
|
-
undefinedSort *= -1;
|
|
3369
|
-
}
|
|
3370
|
-
return undefinedSort;
|
|
3370
|
+
sortInt = aUndefined && bUndefined ? 0 : aUndefined ? columnInfo.sortUndefined : -columnInfo.sortUndefined;
|
|
3371
3371
|
}
|
|
3372
3372
|
}
|
|
3373
|
+
if (sortInt === 0) {
|
|
3374
|
+
sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
|
|
3375
|
+
}
|
|
3373
3376
|
|
|
3374
|
-
//
|
|
3375
|
-
let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
|
|
3377
|
+
// If sorting is non-zero, take care of desc and inversion
|
|
3376
3378
|
if (sortInt !== 0) {
|
|
3377
3379
|
if (isDesc) {
|
|
3378
3380
|
sortInt *= -1;
|