I have a list of elements which one of the property is type, adn its values: { footprint, platform, roving } I am trying to sort the list following the next criteria: platform > footprint > roving
Since alphbetical order footprint is before platform, sorting by the field is not working as expected and I don't know exactly how to implement a custom sort callback to do it. I am using https://vadimdez.github.io/ngx-order-pipe/ module and here is my try:
template
...
<tr *ngFor="let platform of platforms | orderBy: order: false: true: sortCriteria; let i = index;">
...
...
component
...
order: string[] = ['type', 'name'];
...
sortCriteria(itemA, itemB) {
if (itemA.type == 'platform') return 1;
if (itemB.type == 'platform') return -1;
if ((itemA.type == 'footprint') && (itemB.type == 'roving')) return 1
if (itemA.type == 'roving') return -1
}
...
I will appreciate some ideas to get this sort works as expected.