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