Skip to content

Commit 6429495

Browse files
committed
feat: add isDesc to sortingFn
1 parent b487f56 commit 6429495

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

docs/api/features/sorting.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Returns whether this column is sorted.
201201
202202
### `getFirstSortDir`
203203
204-
```tsx
204+
```tsx
205205
getFirstSortDir: () => SortDirection
206206
```
207207
@@ -256,7 +256,7 @@ const column = columnHelper.data('key', {
256256
const table = useReactTable({
257257
columns: [column],
258258
sortingFns: {
259-
myCustomSorting: (rowA: any, rowB: any, columnId: any): number =>
259+
myCustomSorting: (rowA: any, rowB: any, columnId: any, isDesc: boolean): number =>
260260
rowA.getValue(columnId).value < rowB.getValue(columnId).value ? 1 : -1,
261261
},
262262
})

docs/guide/sorting.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ const table = useReactTable({
199199
getCoreRowModel: getCoreRowModel(),
200200
getSortedRowModel: getSortedRowModel(),
201201
sortingFns: { //add a custom sorting function
202-
myCustomSortingFn: (rowA, rowB, columnId) => {
203-
return rowA.original[columnId] > rowB.original[columnId] ? 1 : rowA.original[columnId] < rowB.original[columnId] ? -1 : 0
202+
myCustomSortingFn: (rowA, rowB, columnId, isDesc) => {
203+
return rowA.original[columnId] > rowB.original[columnId] ? 1 : rowA.original[columnId] < rowB.original[columnId] ? -1 : 0
204204
},
205205
},
206206
})
@@ -302,7 +302,7 @@ const columns = [
302302

303303
By default, the ability to remove sorting while cycling through the sorting states for a column is enabled. You can disable this behavior using the `enableSortingRemoval` table option. This behavior is useful if you want to ensure that at least one column is always sorted.
304304

305-
The default behavior when using either the `getToggleSortingHandler` or `toggleSorting` APIs is to cycle through the sorting states like this:
305+
The default behavior when using either the `getToggleSortingHandler` or `toggleSorting` APIs is to cycle through the sorting states like this:
306306

307307
`'none' -> 'desc' -> 'asc' -> 'none' -> 'desc' -> 'asc' -> ...`
308308

packages/table-core/src/features/Sorting.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface SortingTableState {
3232
}
3333

3434
export interface SortingFn<TData extends RowData> {
35-
(rowA: Row<TData>, rowB: Row<TData>, columnId: string): number
35+
(rowA: Row<TData>, rowB: Row<TData>, columnId: string, isDesc?: boolean): number
3636
}
3737

3838
export type CustomSortingFns<TData extends RowData> = Record<

packages/table-core/src/utils/getSortedRowModel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function getSortedRowModel<TData extends RowData>(): (
7474
}
7575

7676
if (sortInt === 0) {
77-
sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)
77+
sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id, isDesc)
7878
}
7979

8080
// If sorting is non-zero, take care of desc and inversion

0 commit comments

Comments
 (0)