fabric8-stack-analysis
Version:
Fabric8 Stack Analysis Feature
20 lines (17 loc) • 583 B
text/typescript
import { Injectable, Pipe, PipeTransform } from '@angular/core';
({
name: 'orderBy'
})
()
export class TableOrderByPipe implements PipeTransform {
public transform(items: Array<any>, fieldName: string, direction: string): Array<any> {
let newItems: Array<any> = items.sort((a: any, b: any) => {
if (direction.toLowerCase() === 'up') {
return a[fieldName] < b[fieldName] ? -1 : 1;
} else {
return a[fieldName] > b[fieldName] ? -1 : 1;
}
});
return newItems;
}
}