I am working with a mat-table and have used GET to display my data. I now want to sort the data in ascending order based on the db-nr from my JSON.
Here is an excerpt from my JSON:
{
"period": 12.0,
"amount": 0.0,
"name": "Test1",
"mandantKagId": 0.0,
"db-nr": 5
},
{
"period": 12.0,
"amount": 0.0,
"name": "Test2",
"mandantKagId": 0.0,
"db-nr": 2
},
{
"period": 12.0,
"amount": 0.0,
"name": "Test3",
"mandantKagId": 0.0,
"db-nr": 4
}
// Typescript code
// Populating the table with data
private loadData() {
this.planBwaService.getAllPlanBwaData(yearString).subscribe(
(resp: any) => {
const planBwa = resp.success ? resp.bwaResult.planBwa : null;
const data = planBwa['0'];
const allYearlyResults = planBwa.yearlyResults;
const yearlyResults = allYearlyResults['0'];
if (null !== data && data && yearlyResults && yearlyResults !== null) {
this.isLoading = false;
const rows = [];
const planBwaData: string[] = [];
const names = _.uniq(data.map((d) => d.name)) as string[];
for (const n of names) {
planBwaData[n] = data.filter((d) => d.name === n);
if (planBwaData[n].length > 0) {
const row: any = { name: planBwaData[n][0].name, values: {}, note: '', mandantKagId: planBwaData[n][0].mandantKagId };
for (const item of planBwaData[n]) {
row[item.period] = this.transformAmount(item.amount);
}
const yrNameItem = yearlyResults.find((yr) => yr.name === n);
row.values.currentYear = (yrNameItem && yrNameItem !== null) ? this.transformAmount(yrNameItem.amount) : null;
rows.push(row);
}
}
this.dataSource = new MatTableDataSource<PlanBwa>(rows);
this.dataSource.data = rows;
}
);
}
Could you please provide some guidance on how I can proceed with this implementation?