File

src/lib/pipes/sort-by/sort-by.pipe.ts

Metadata

Methods

transform
transform(data: any[], sortField: string, sortOrder: string)
Parameters :
Name Type Optional
data any[] No
sortField string No
sortOrder string No
Returns : any[]
import { Pipe, PipeTransform } from '@angular/core';
/* tslint:disable */
import { orderBy } from 'lodash-es';
/* tslint:enable */

@Pipe({
  name: 'sortBy'
})
export class SortByPipe implements PipeTransform {

  transform(data: any[], sortField: string, sortOrder: string): any[] {
    if (!data || !data.length || sortOrder === '' || !sortOrder) { return data; }
    if (!sortField || sortField === '') {
      data = data.map(e => e.trim());
      if (sortOrder === 'asc') {
        return data.sort();
      } else {
        return data.sort().reverse();
      }
    }
    data.forEach((obj) => {
      obj[sortField] = obj[sortField].trim();
    });
    return orderBy(data, [sortField], [sortOrder]);
  }

}

results matching ""

    No results matching ""