diff --git a/src/app/showcase/doc/table/columntoggledoc.ts b/src/app/showcase/doc/table/columntoggledoc.ts
index 01340ae52bc..fa27336229a 100644
--- a/src/app/showcase/doc/table/columntoggledoc.ts
+++ b/src/app/showcase/doc/table/columntoggledoc.ts
@@ -1,4 +1,4 @@
-import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core';
+import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Code } from '@domain/code';
import { Product } from '@domain/product';
import { ProductService } from '@service/productservice';
@@ -12,47 +12,46 @@ interface Column {
template: `
This demo uses a multiselect component to implement toggleable columns.
-
-
-
-
-
-
-
-
- Code |
-
- {{ col.header }}
- |
-
-
-
-
- {{ product.code }} |
-
- {{ product[col.field] }}
- |
-
-
-
-
-
+
+
+
+
+
+
+
+
+ Code |
+
+ {{ col.header }}
+ |
+
+
+
+
+ {{ product.code }} |
+
+ {{ product[col.field] }}
+ |
+
+
+
+
+
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ColumnToggleDoc {
- products!: Product[];
+ products: Product[];
- cols!: Column[];
+ cols: Column[];
- selectedColumns!: Column[];
+ _selectedColumns: Column[];
- constructor(private productService: ProductService, private cd: ChangeDetectorRef) {}
+ constructor(private productService: ProductService) {}
- loadDemoData() {
+ ngOnInit() {
this.productService.getProductsMini().then((data) => {
this.products = data;
- this.cd.markForCheck();
});
this.cols = [
@@ -61,7 +60,16 @@ export class ColumnToggleDoc {
{ field: 'quantity', header: 'Quantity' }
];
- this.selectedColumns = this.cols;
+ this._selectedColumns = this.cols;
+ }
+
+ get selectedColumns(): Column[] {
+ return this._selectedColumns;
+ }
+
+ set selectedColumns(val: Column[]) {
+ //restore original order
+ this._selectedColumns = this.cols.filter((col) => val.includes(col));
}
code: Code = {
@@ -148,18 +156,17 @@ interface Column {
providers: [ProductService]
})
export class TableColumnToggleDemo implements OnInit{
- products!: Product[];
+ products: Product[];
- cols!: Column[];
+ cols: Column[];
- selectedColumns!: Column[];
+ _selectedColumns: Column[];
- constructor(private productService: ProductService, private cd: ChangeDetectorRef) {}
+ constructor(private productService: ProductService) {}
ngOnInit() {
this.productService.getProductsMini().then((data) => {
this.products = data;
- this.cd.markForCheck();
});
this.cols = [
@@ -168,9 +175,17 @@ export class TableColumnToggleDemo implements OnInit{
{ field: 'quantity', header: 'Quantity' }
];
- this.selectedColumns = this.cols;
+ this._selectedColumns = this.cols;
}
+ get selectedColumns(): Column[] {
+ return this._selectedColumns;
+ }
+
+ set selectedColumns(val: Column[]) {
+ //restore original order
+ this._selectedColumns = this.cols.filter((col) => val.includes(col));
+ }
}`,
data: `{
id: '1000',