From 57949c6c80e99a8bbe5d000336431e5bc57f8fa8 Mon Sep 17 00:00:00 2001 From: Harsh Jadhav Date: Fri, 6 Jun 2025 08:00:26 +0000 Subject: [PATCH] Fix: Add column sorting changes --- .../src/lib/benchmark/benchmark.component.ts | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/libs/ui/src/lib/benchmark/benchmark.component.ts b/libs/ui/src/lib/benchmark/benchmark.component.ts index e773caecf..c2d1aa3b9 100644 --- a/libs/ui/src/lib/benchmark/benchmark.component.ts +++ b/libs/ui/src/lib/benchmark/benchmark.component.ts @@ -13,18 +13,21 @@ import { GfValueComponent } from '@ghostfolio/ui/value'; import { CommonModule } from '@angular/common'; import { CUSTOM_ELEMENTS_SCHEMA, + AfterViewInit, ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, OnDestroy, - Output + Output, + ViewChild } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { MatDialog } from '@angular/material/dialog'; import { MatMenuModule } from '@angular/material/menu'; -import { MatTableModule } from '@angular/material/table'; +import { MatSort, MatSortModule } from '@angular/material/sort'; +import { MatTableDataSource, MatTableModule } from '@angular/material/table'; import { ActivatedRoute, Router, RouterModule } from '@angular/router'; import { isNumber } from 'lodash'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; @@ -41,6 +44,7 @@ import { BenchmarkDetailDialogParams } from './benchmark-detail-dialog/interface GfValueComponent, MatButtonModule, MatMenuModule, + MatSortModule, MatTableModule, NgxSkeletonLoaderModule, RouterModule @@ -50,7 +54,9 @@ import { BenchmarkDetailDialogParams } from './benchmark-detail-dialog/interface styleUrls: ['./benchmark.component.scss'], templateUrl: './benchmark.component.html' }) -export class GfBenchmarkComponent implements OnChanges, OnDestroy { +export class GfBenchmarkComponent + implements AfterViewInit, OnChanges, OnDestroy +{ @Input() benchmarks: Benchmark[]; @Input() deviceType: string; @Input() hasPermissionToDeleteItem: boolean; @@ -59,6 +65,9 @@ export class GfBenchmarkComponent implements OnChanges, OnDestroy { @Output() itemDeleted = new EventEmitter(); + @ViewChild(MatSort) sort: MatSort; + + public dataSource = new MatTableDataSource([]); public displayedColumns = [ 'name', 'date', @@ -95,8 +104,26 @@ export class GfBenchmarkComponent implements OnChanges, OnDestroy { }); } + public ngAfterViewInit() { + this.dataSource.sort = this.sort; + + // Custom sorting for the 'change' column which uses nested properties + this.dataSource.sortingDataAccessor = ( + item: Benchmark, + property: string + ) => { + switch (property) { + case 'change': + return item?.performances?.allTimeHigh?.performancePercent || 0; + default: + return item[property]; + } + }; + } + public ngOnChanges() { if (this.benchmarks) { + this.dataSource.data = this.benchmarks; this.isLoading = false; }