*ngFor="let match of virtual | groupby : 'gameid'
I have this code snippet that uses a pipe to group by the 'gameid' field, which consists of numbers like 23342341.
Now, I need help sorting this array in ascending order based on the gameid. Can anyone provide me with the necessary code for this?
import { Pipe, PipeTransform, Component, NgModule} from '@angular/core';
/**
* Custom GroupbyPipe implementation.
*/
@Pipe({
name: 'groupby',
})
export class GroupbyPipe implements PipeTransform {
/**
* Transform function to sort an array by a specific property.
*/
transform(array: Array<string>, args: string): Array<string> {
if (array !== undefined) {
array.sort((a: any, b: any) => {
if (a[args] < b[args]) {
return -1;
} else if (a[args] > b[args]) {
return 1;
} else {
return 0;
}
});
}
return array;
}
}
This is my customized pipe for sorting arrays based on the specified property.
I tried finding solutions on Google but none of them worked. Could someone guide me on how to successfully sort my array using the pipe according to the gameid (integer) property?