According to this question -> Ascending and Descending Sort in Angular 4
I've made the same pipe, but it can't sort numbers naturally. I mean 2 is > then 11.
How can this pipe be modified to sort both string and numbers?
@Pipe({
name: 'orderBy'
})
export class OrderByPipe implements PipeTransform {
transform(records: Array<any>, args?: any): any {
if (records && records.length > 0) {
return records.sort(function (a, b) {
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;
}
});
}
}
}