added sorting to management pages

This commit is contained in:
Jonas Winkler
2020-11-08 16:58:06 +01:00
parent 44a61421a9
commit 0947d8a3e2
10 changed files with 121 additions and 23 deletions

View File

@@ -0,0 +1,8 @@
import { SortableDirective } from './sortable.directive';
describe('SortableDirective', () => {
it('should create an instance', () => {
const directive = new SortableDirective();
expect(directive).toBeTruthy();
});
});

View File

@@ -0,0 +1,30 @@
import { Directive, EventEmitter, Input, Output } from '@angular/core';
export interface SortEvent {
column: string;
direction: string;
}
const rotate: {[key: string]: string} = { 'asc': 'des', 'des': '', '': 'asc' };
@Directive({
selector: 'th[sortable]',
host: {
'[class.asc]': 'direction === "asc"',
'[class.des]': 'direction === "des"',
'(click)': 'rotate()'
}
})
export class SortableDirective {
constructor() { }
@Input() sortable: string = '';
@Input() direction: string = '';
@Output() sort = new EventEmitter<SortEvent>();
rotate() {
this.direction = rotate[this.direction];
this.sort.emit({column: this.sortable, direction: this.direction});
}
}