I am facing an issue with a class named 'scenario' that has properties such as 'id', 'name', and 'number' among others.
In the HTML, scenarios are displayed in this format:
<mat-grid-list [cols]="breakpoint" rowHeight="4:4" [@gridAnimation]="(scenarios$ | async)?.length" (window:resize)="onResize($event)">
<mat-grid-tile *ngFor="let scenario of filteredScenarios$ | async ">
<app-scenario-card [scenario]="scenario" [routerLink]="['/scenario', scenario.id]"></app-scenario-card>
</mat-grid-tile>
</mat-grid-list>
My question is, can I sort the displayed tiles of scenarios by a selected property like name, id, or number? Most resources I've found regarding sorting focus on tables or grids.
If it is possible, could someone provide me with an example or approach to achieve this?
Thank you in advance.
Also, changing from grid-list to table is not an option for me.
The 'Scenario' class has the following properties:
export class Scenario {
id: number;
scenarioName: string;
scenarioDescription: string;
periods: number; }
I already have a search box for filtering data. Now, I need help implementing a sort function for properties like id, scenarioName, and periods using buttons or dropdown menus.
The code for filtering currently looks like this:
this.scenarios$ = this.scenariosService.getScenarios();
this.filter = new FormControl('');
this.filter$ = this.filter.valueChanges.pipe(startWith(''));
this.filteredScenarios$ = combineLatest(this.scenarios$, this.filter$).pipe(
map(([Scenario, filterString]) => Scenario.filter(scenario => scenario.scenarioName.indexOf(filterString) !== -1)));