-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sort): refactor and add support for multiple columns
- Loading branch information
Hjalmers
committed
Jan 26, 2023
1 parent
e0f0a6e
commit e3d2cf2
Showing
9 changed files
with
179 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { Order } from '../enums/order.enum'; | ||
import { TableRow } from './table-row.interface'; | ||
|
||
export interface TableSort { | ||
sortBy: string; | ||
sortByOrder: Order; | ||
export type GtSortOrder<R = TableRow> = Array<GtSortConfig<R>>; | ||
export interface GtSortConfig<R = {}> { | ||
key: keyof R; | ||
order: GtOrder; | ||
} | ||
|
||
export type GtOrder = 'asc' | 'desc'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,35 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
import { Order } from '../enums/order.enum'; | ||
import { GtSortOrder } from '../models/table-sort.interface'; | ||
|
||
@Pipe({ | ||
name: 'sortClass', | ||
standalone: true, | ||
}) | ||
export class SortClassPipe implements PipeTransform { | ||
transform( | ||
selection: { sortBy: string; sortByOrder: Order } | any, | ||
property: string, | ||
aria = false | ||
sortOrder: GtSortOrder | null, | ||
key: string, | ||
context: 'class' | 'aria' | 'order' = 'class' | ||
): string | null { | ||
return selection?.sortBy === property | ||
? !aria | ||
? 'gt-sort-' + selection.sortByOrder | ||
: selection.sortByOrder + 'ending' | ||
: !aria | ||
? '' | ||
: null; | ||
const sortIndex = sortOrder | ||
? sortOrder.findIndex((s) => s.key === key) | ||
: -1; | ||
if (context === 'aria') { | ||
if (sortIndex === -1 || !sortOrder) { | ||
return null; | ||
} else { | ||
return `${sortOrder[sortIndex].order}ending`; | ||
} | ||
} else if (context === 'class') { | ||
if (sortIndex === -1 || !sortOrder) { | ||
return ''; | ||
} else { | ||
return `gt-sort-${sortOrder[sortIndex].order}`; | ||
} | ||
} else { | ||
return (sortOrder && sortOrder?.length === 1) || sortIndex < 0 | ||
? null | ||
: sortIndex + 1 + ''; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.