From 0d3f25a00d2564ee78b2f38eb391f4e4b1df0ea7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=87etin?=
<69278826+cetincakiroglu@users.noreply.github.com>
Date: Thu, 24 Jul 2025 18:21:45 +0300
Subject: [PATCH] fixes #91
---
src/app/pages/uikit/tabledemo.ts | 103 +++++++++++++++----------------
1 file changed, 51 insertions(+), 52 deletions(-)
diff --git a/src/app/pages/uikit/tabledemo.ts b/src/app/pages/uikit/tabledemo.ts
index 8a87bd5..0b032d8 100644
--- a/src/app/pages/uikit/tabledemo.ts
+++ b/src/app/pages/uikit/tabledemo.ts
@@ -18,6 +18,7 @@ import { IconFieldModule } from 'primeng/iconfield';
import { TagModule } from 'primeng/tag';
import { Customer, CustomerService, Representative } from '../service/customer.service';
import { Product, ProductService } from '../service/product.service';
+import {ObjectUtils} from "primeng/utils";
interface expandedRows {
[key: string]: boolean;
@@ -238,80 +239,62 @@ interface expandedRows {
Row Expansion
-
+
- |
-
- Name
-
- |
+ |
+ Name |
Image |
-
- Price
-
- |
-
- Category
-
- |
-
- Reviews
-
- |
-
- Status
-
- |
+ Price |
+ Category |
+ Reviews |
+ Status |
|
-
+
|
- {{ product.name }} |
- ![]() |
- {{ product.price | currency: 'USD' }} |
- {{ product.category }} |
-
-
+ | {{ product.name }} |
+
+
+ |
+ {{ product.price | currency: 'USD' }} |
+ {{ product.category }} |
+
+
|
-
+
|
-
+
-
-
+
+ Orders for {{ product.name }}
+
- |
- Id
-
- |
+ Id |
Customer
-
- |
-
- Date
-
+
|
+ Date |
Amount
-
+
|
-
+ |
Status
-
+
|
|
@@ -321,12 +304,14 @@ interface expandedRows {
{{ order.id }} |
{{ order.customer }} |
{{ order.date }} |
- {{ order.amount | currency: 'USD' }} |
- {{ order.status }}
+ {{ order.amount | currency: 'USD' }}
|
-
+
+ |
+
+
|
|
@@ -504,12 +489,26 @@ export class TableDemo implements OnInit {
}
expandAll() {
- if (!this.isExpanded) {
- this.products.forEach((product) => (product && product.name ? (this.expandedRows[product.name] = true) : ''));
+ if(ObjectUtils.isEmpty(this.expandedRows)) {
+ this.expandedRows = this.products.reduce(
+ (acc, p) => {
+ if (p.id) {
+ acc[p.id] = true;
+ }
+ return acc;
+ },
+ {} as { [key: string]: boolean }
+ );
+ this.isExpanded = true;
} else {
- this.expandedRows = {};
+ this.collapseAll()
}
- this.isExpanded = !this.isExpanded;
+
+ }
+
+ collapseAll() {
+ this.expandedRows = {};
+ this.isExpanded = false;
}
formatCurrency(value: number) {