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) {