diff --git a/dashboard/src/app/artist.component.html b/dashboard/src/app/artist.component.html index 444f4c1..7fff891 100644 --- a/dashboard/src/app/artist.component.html +++ b/dashboard/src/app/artist.component.html @@ -1,7 +1,7 @@

{{albumName}}

\ No newline at end of file diff --git a/dashboard/src/app/sortby.pipe.ts b/dashboard/src/app/sortby.pipe.ts index 12c498f..12e0433 100644 --- a/dashboard/src/app/sortby.pipe.ts +++ b/dashboard/src/app/sortby.pipe.ts @@ -1,29 +1,24 @@ -// Thank to http://4dev.tech/2016/09/angular2-how-to-sort-a-json-dataset-by-field/ +// Thank to http://4dev.tech/2016/09/angular2-how-to-sort-a-json-dataset-by-field/ for the pipe +// Thank to http://stackoverflow.com/questions/28560801/javascript-sorting-array-by-multiple-criteria for the multi-args part import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: "sortBy"}) export class SortPipe implements PipeTransform { - transform(array: Array, args: string): Array { - array.sort((a: any, b: any) => { - if (a[args] == undefined && b[args] == undefined) { - return 0; - } - if (a[args] == undefined && b[args] != undefined) { - return -1; - } - if (a[args] != undefined && b[args] == undefined) { - return 1; - } + transform(array: Array, ...args: any[]): Array { + console.log("test: " + args); + array.sort((a: any, b: any) => { + for (let i = 0; i < array.length; i++) { + let arg = args[i]; - if ( a[args] < b[args] ){ - return -1; - }else if( a[args] > b[args] ){ - return 1; - }else{ - return 0; - } - }); + if (a[arg] == undefined && b[arg] != undefined) return -1; + if (a[arg] != undefined && b[arg] == undefined) return 1; + + if (a[arg] < b[arg]) return -1; + if (a[arg] > b[arg]) return 1; + } + return 0; + }); return array; } } \ No newline at end of file