Skip to content

Commit

Permalink
feat: add sortDirection to customSort
Browse files Browse the repository at this point in the history
  • Loading branch information
Domino987 committed Mar 18, 2022
1 parent 0ee9b20 commit 23b02f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/utils/data-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,9 @@ export default class DataManager {
if (this.orderDirection === 'desc') {
result = list.sort((a, b) => columnDef.customSort(b, a, 'row', 'desc'));
} else {
result = list.sort((a, b) => columnDef.customSort(a, b, 'row'));
result = list.sort((a, b) =>
columnDef.customSort(a, b, 'row', this.orderDirection)
);
}
} else {
result = list.sort(
Expand Down Expand Up @@ -1135,8 +1137,20 @@ export default class DataManager {
if (columnDef.customSort) {
return list.sort(
columnDef.tableData.groupSort === 'desc'
? (a, b) => columnDef.customSort(b.value, a.value, 'group')
: (a, b) => columnDef.customSort(a.value, b.value, 'group')
? (a, b) =>
columnDef.customSort(
b.value,
a.value,
'group',
columnDef.tableData.groupSort
)
: (a, b) =>
columnDef.customSort(
a.value,
b.value,
'group',
columnDef.tableData.groupSort
)
);
} else {
return list.sort(
Expand Down
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ export interface Column<RowData extends object> {
customSort?: (
data1: RowData,
data2: RowData,
type: 'row' | 'group'
type: 'row' | 'group',
sortDirection?: 'desc' | 'asc'
) => number;
//customExport prop handle flattening of data at column level before passing data to exporter. Note exportMenu.exportFunc is an alternative to handle data change at exporter level
customExport?: (rowData: RowData) => unknown;
Expand Down

0 comments on commit 23b02f1

Please sign in to comment.