Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
refactor(DataTable): sort functions has now access to sort direction
Browse files Browse the repository at this point in the history
BREAKING CHANGE: DataTable sorting may not work like before.
  • Loading branch information
valentingavran committed Oct 18, 2022
1 parent e05192b commit caab6cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type DataTableHeader<T = any> = {
filterable?: boolean;
hidden?: boolean;
hiddenOnMobile?: boolean;
sort?(a: DataTableItem<T>, b: DataTableItem<T>): number;
sort?(a: DataTableItem<T>, b: DataTableItem<T>, direction: SortSetting['direction']): number;
sortable?: boolean;
text: string;
value: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ export class DataService {
// if sort function is defined in headers, use it
const header = headers.find(header => header.value === option.value);
if (header?.sort) {
const sort = header.sort(a, b);

if (option.direction === 'desc') return sort * -1;
return sort;
const sort = header.sort(a, b, option.direction);
if (sort !== 0) return sort;
continue;
}

const aValue = a[option.value];
Expand Down

0 comments on commit caab6cd

Please sign in to comment.