merge from ecomp a88f0072 - Modern UI
[vid.git] / vid-webpack-master / src / app / shared / pipes / order / orderBy.pipe.ts
1 import { Pipe, PipeTransform } from '@angular/core';
2 import * as _ from 'lodash';
3 @Pipe({  name: 'orderBy' })
4 export class OrderByPipe implements PipeTransform {
5
6   transform(records: any[], args: any = {}): any {
7     args.direction =  !_.isNil(args.direction) ? args.direction : 1;
8
9     if(!_.isNil(records)){
10       return records.sort(function(a, b){
11         if(args.property){
12           if(a[args.property] < b[args.property]){
13             return -1 * args.direction;
14           }
15           else if( a[args.property] > b[args.property]){
16             return 1 * args.direction;
17           }
18           else{
19             return 0;
20           }
21         }else {
22           if(a < b){
23             return -1 * args.direction;
24           }
25           else if( a > b){
26             return 1 * args.direction;
27           }
28           else{
29             return 0;
30           }
31         }
32       });
33     }
34   };
35 }