Added dates to table and date Sorting
This commit is contained in:
@@ -8,6 +8,10 @@ export function sortByStringAscending<T>(items: T[], key: (T) => string) {
|
||||
return items.sort((a, b) => key(a).localeCompare(key(b)));
|
||||
}
|
||||
|
||||
export function sortByDateAscending<T>(items: T[], key: (T) => Date) {
|
||||
return items.sort((a, b) => <any>key(b) - <any>key(a));
|
||||
}
|
||||
|
||||
export function getNumberForPriority(priority: Priority): number {
|
||||
switch (priority) {
|
||||
case Priority.High:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {sortByNumberAscending, sortByStringAscending} from './sorting.service';
|
||||
import {sortByNumberAscending, sortByStringAscending, sortByDateAscending} from './sorting.service';
|
||||
import {Priority} from './backend.service';
|
||||
|
||||
export abstract class TableComponentBase<T> {
|
||||
@@ -32,6 +32,19 @@ export abstract class TableComponentBase<T> {
|
||||
}
|
||||
}
|
||||
|
||||
protected doDateSort(by: string, key: (item: T) => Date) {
|
||||
if (this.sortBy === by) {
|
||||
this.sortDescending = !this.sortDescending;
|
||||
} else {
|
||||
this.sortBy = by;
|
||||
}
|
||||
|
||||
this.items = sortByDateAscending(this.items, key);
|
||||
if (this.sortDescending) {
|
||||
this.items = this.items.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
public getAllPriorities(): string[] {
|
||||
return Object.values(Priority);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user