Skip to content

Instantly share code, notes, and snippets.

@mdmoin7
Last active July 3, 2022 07:18
Show Gist options
  • Save mdmoin7/73eea358d03194d6fc17c65f379df0e3 to your computer and use it in GitHub Desktop.
Save mdmoin7/73eea358d03194d6fc17c65f379df0e3 to your computer and use it in GitHub Desktop.
/*
*ngFor="let c of oneDimArray | sortBy:'asc'"
*ngFor="let c of arrayOfObjects | sortBy:'asc':'propertyName'"
*/
import { Pipe, PipeTransform } from '@angular/core';
import { orderBy } from 'lodash';
@Pipe({ name: 'sortBy' })
export class SortByPipe implements PipeTransform {
transform(value: any[], order = '', column: string = ''): any[] {
if (!value || order === '' || !order) { return value; } // no array
if (value.length <= 1) { return value; } // array with only one item
if (!column || column === '') {
if(order==='asc'){return value.sort()}
else{return value.sort().reverse();}
} // sort 1d array
return orderBy(value, [column], [order]);
}
}
@ReeceXmen
Copy link

The above issue started to happen due to lodash changes, you can change the type for the argument order:any

Thank You !!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment