From 928b5a10a70c52a6a4d6759a12607bbb541a13ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Wed, 3 Jan 2024 14:13:02 +0300 Subject: [PATCH 1/3] Improve DataTable demo performance --- src/app/components/demo/deferreddemo.css | 10 + src/app/components/demo/deferreddemo.ts | 61 ++++ src/app/components/demo/ng-package.json | 6 + src/app/components/demo/public_api.ts | 1 + src/app/showcase/doc/table/basicdoc.ts | 48 +-- src/app/showcase/doc/table/celleditdoc.ts | 120 ++++---- .../doc/table/checkboxselectiondoc.ts | 58 ++-- src/app/showcase/doc/table/columngroupdoc.ts | 4 +- .../doc/table/columnresizeexpandmodedoc.ts | 48 +-- .../doc/table/columnresizefitmodedoc.ts | 48 +-- .../table/columnresizescrollablemodedoc.ts | 48 +-- .../showcase/doc/table/columnselectiondoc.ts | 8 +- src/app/showcase/doc/table/columntoggledoc.ts | 50 ++-- src/app/showcase/doc/table/contextmenudoc.ts | 50 ++-- .../doc/table/controlledselectiondoc.ts | 60 ++-- src/app/showcase/doc/table/customersdoc.ts | 8 +- src/app/showcase/doc/table/customsortdoc.ts | 8 +- src/app/showcase/doc/table/dynamicdoc.ts | 4 +- .../doc/table/expandablerowgroupdoc.ts | 104 +++---- src/app/showcase/doc/table/exportdoc.ts | 60 ++-- src/app/showcase/doc/table/filtermenudoc.ts | 8 +- src/app/showcase/doc/table/filterrowdoc.ts | 196 +++++++------ .../showcase/doc/table/flexiblescrolldoc.ts | 8 +- .../showcase/doc/table/frozencolumnsdoc.ts | 70 ++--- src/app/showcase/doc/table/frozenrowsdoc.ts | 76 ++--- src/app/showcase/doc/table/gridlinesdoc.ts | 48 +-- .../doc/table/horizontalandverticaldoc.ts | 8 +- src/app/showcase/doc/table/lazyloaddoc.ts | 142 ++++----- .../doc/table/multiplecolumnsortdoc.ts | 52 ++-- .../doc/table/multipleselectiondoc.ts | 56 ++-- .../doc/table/pageonlyselectiondoc.ts | 58 ++-- .../showcase/doc/table/paginatorbasicdoc.ts | 72 ++--- .../showcase/doc/table/paginatorlocaledoc.ts | 74 ++--- .../doc/table/paginatorprogrammaticdoc.ts | 4 +- src/app/showcase/doc/table/productsdoc.ts | 276 +++++++++--------- .../doc/table/radiobuttonselectiondoc.ts | 56 ++-- src/app/showcase/doc/table/reorderdoc.ts | 52 ++-- .../showcase/doc/table/responsivescrolldoc.ts | 58 ++-- .../showcase/doc/table/responsivestackdoc.ts | 54 ++-- src/app/showcase/doc/table/roweditdoc.ts | 138 ++++----- src/app/showcase/doc/table/rowexpanddoc.ts | 8 +- .../showcase/doc/table/rowspangroupingdoc.ts | 88 +++--- .../showcase/doc/table/selectioneventsdoc.ts | 8 +- .../showcase/doc/table/singlecolumnsortdoc.ts | 8 +- .../showcase/doc/table/singleselectiondoc.ts | 48 +-- src/app/showcase/doc/table/sizedoc.ts | 48 +-- src/app/showcase/doc/table/statefuldoc.ts | 8 +- src/app/showcase/doc/table/stripeddoc.ts | 44 +-- src/app/showcase/doc/table/styledoc.ts | 54 ++-- .../doc/table/subheadergroupingdoc.ts | 100 +++---- src/app/showcase/doc/table/tabledoc.module.ts | 5 +- src/app/showcase/doc/table/templatedoc.ts | 78 ++--- .../showcase/doc/table/verticalscrolldoc.ts | 48 +-- .../showcase/doc/table/virtualscrolldoc.ts | 8 +- .../doc/table/virtualscrolllazydoc.ts | 56 ++-- 55 files changed, 1550 insertions(+), 1369 deletions(-) create mode 100755 src/app/components/demo/deferreddemo.css create mode 100755 src/app/components/demo/deferreddemo.ts create mode 100644 src/app/components/demo/ng-package.json create mode 100644 src/app/components/demo/public_api.ts diff --git a/src/app/components/demo/deferreddemo.css b/src/app/components/demo/deferreddemo.css new file mode 100755 index 00000000000..02eb23994ea --- /dev/null +++ b/src/app/components/demo/deferreddemo.css @@ -0,0 +1,10 @@ +.demo-section-loading { + display: grid; + place-items: center; + padding: 2rem; + border-radius: 10px; + margin-bottom: 1rem; + font-size: 2rem; + height: 350px; + background: var(--maskbg); +} \ No newline at end of file diff --git a/src/app/components/demo/deferreddemo.ts b/src/app/components/demo/deferreddemo.ts new file mode 100755 index 00000000000..e8b1cfb3e48 --- /dev/null +++ b/src/app/components/demo/deferreddemo.ts @@ -0,0 +1,61 @@ +import { CommonModule, isPlatformBrowser } from '@angular/common'; +import { Component, ElementRef, EventEmitter, Inject, Input, NgModule, OnInit, Output, PLATFORM_ID } from '@angular/core'; +import { SharedModule } from 'primeng/api'; + +@Component({ + selector: 'p-deferred-demo', + template: ` +
Loading...
+ + + + `, + styleUrls: ['./deferreddemo.css'], + host: { + class: 'p-element' + } +}) +export class DeferredDemo implements OnInit { + visible: boolean = false; + + observer = null; + + timeout = null; + + @Input() options: any; + + @Output() load: EventEmitter = new EventEmitter(); + + constructor(public el: ElementRef, @Inject(PLATFORM_ID) private platformId: any) {} + + ngOnInit() { + if (isPlatformBrowser(this.platformId)) { + this.observer = new IntersectionObserver(([entry]) => { + clearTimeout(this.timeout); + + if (entry.isIntersecting) { + this.timeout = setTimeout(() => { + this.visible = true; + this.observer.unobserve(this.el.nativeElement); + this.load.emit(); + }, 350); + } + }, this.options); + + this.observer.observe(this.el.nativeElement); + } + } + ngOnDestroy() { + if (!this.visible && this.el.nativeElement) { + this.observer?.unobserve(this.el.nativeElement); + } + clearTimeout(this.timeout); + } +} + +@NgModule({ + imports: [CommonModule, SharedModule], + exports: [DeferredDemo, SharedModule], + declarations: [DeferredDemo] +}) +export class DeferredDemoModule {} diff --git a/src/app/components/demo/ng-package.json b/src/app/components/demo/ng-package.json new file mode 100644 index 00000000000..ab5467eb7e4 --- /dev/null +++ b/src/app/components/demo/ng-package.json @@ -0,0 +1,6 @@ +{ + "$schema": "ng-packagr/ng-package.schema.json", + "lib": { + "entryFile": "public_api.ts" + } + } \ No newline at end of file diff --git a/src/app/components/demo/public_api.ts b/src/app/components/demo/public_api.ts new file mode 100644 index 00000000000..75d9b10f247 --- /dev/null +++ b/src/app/components/demo/public_api.ts @@ -0,0 +1 @@ +export * from './deferreddemo'; diff --git a/src/app/showcase/doc/table/basicdoc.ts b/src/app/showcase/doc/table/basicdoc.ts index 5f95c71ceea..5c8990da1eb 100644 --- a/src/app/showcase/doc/table/basicdoc.ts +++ b/src/app/showcase/doc/table/basicdoc.ts @@ -8,41 +8,43 @@ import { ProductService } from '../../service/productservice'; template: `

DataTable requires a collection to display along with column components for the representation of the data.

-
- - - - Code - Name - Category - Quantity - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ +
+ + + + Code + Name + Category + Quantity + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class BasicDoc implements OnInit { +export class BasicDoc { products!: Product[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); }); } - + code: Code = { basic: ` diff --git a/src/app/showcase/doc/table/celleditdoc.ts b/src/app/showcase/doc/table/celleditdoc.ts index 9ff64f5150e..6b3f9dae977 100644 --- a/src/app/showcase/doc/table/celleditdoc.ts +++ b/src/app/showcase/doc/table/celleditdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -8,71 +8,73 @@ import { ProductService } from '../../service/productservice'; template: `

In-cell editing is enabled by adding pEditableColumn directive to an editable cell that has a p-cellEditor helper component to define the input-output templates for the edit and view modes respectively.

-
- - - - Code - Name - Inventory Status - Price - - - - - - - - - - - {{ product.code }} - - - - - - - - - - {{ product.name }} - - - - - - - - - - {{ product.inventoryStatus }} - - - - - - - - - - {{ product.price | currency : 'USD' }} - - - - - - -
+ +
+ + + + Code + Name + Inventory Status + Price + + + + + + + + + + + {{ product.code }} + + + + + + + + + + {{ product.name }} + + + + + + + + + + {{ product.inventoryStatus }} + + + + + + + + + + {{ product.price | currency : 'USD' }} + + + + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class CellEditDoc implements OnInit { +export class CellEditDoc { products!: Product[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/checkboxselectiondoc.ts b/src/app/showcase/doc/table/checkboxselectiondoc.ts index 88022ecef4e..531fc34e2e5 100644 --- a/src/app/showcase/doc/table/checkboxselectiondoc.ts +++ b/src/app/showcase/doc/table/checkboxselectiondoc.ts @@ -8,43 +8,45 @@ import { ProductService } from '../../service/productservice'; template: `

Multiple selection can also be handled using checkboxes by enabling the selectionMode property of column as multiple.

-
- - - - - - - Code - Name - Category - Quantity - - - - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ +
+ + + + + + + Code + Name + Category + Quantity + + + + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class CheckboxSelectionDoc implements OnInit { +export class CheckboxSelectionDoc { products!: Product[]; selectedProducts!: Product; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/columngroupdoc.ts b/src/app/showcase/doc/table/columngroupdoc.ts index 9757c42be51..5653cf6b074 100644 --- a/src/app/showcase/doc/table/columngroupdoc.ts +++ b/src/app/showcase/doc/table/columngroupdoc.ts @@ -6,6 +6,7 @@ import { Code } from '../../domain/code'; template: `

Columns can be grouped using rowspan and colspan properties.

+
@@ -42,6 +43,7 @@ import { Code } from '../../domain/code';
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -54,7 +56,7 @@ export class ColumnGroupDoc { constructor(private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.sales = [ { product: 'Bamboo Watch', lastYearSale: 51, thisYearSale: 40, lastYearProfit: 54406, thisYearProfit: 43342 }, { product: 'Black Watch', lastYearSale: 83, thisYearSale: 9, lastYearProfit: 423132, thisYearProfit: 312122 }, diff --git a/src/app/showcase/doc/table/columnresizeexpandmodedoc.ts b/src/app/showcase/doc/table/columnresizeexpandmodedoc.ts index 6241e129eb7..ed9b29e73e6 100644 --- a/src/app/showcase/doc/table/columnresizeexpandmodedoc.ts +++ b/src/app/showcase/doc/table/columnresizeexpandmodedoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -8,35 +8,37 @@ import { ProductService } from '../../service/productservice'; template: `

Setting columnResizeMode as expand changes the table width as well.

-
- - - - Code - Name - Category - Quantity - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ +
+ + + + Code + Name + Category + Quantity + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class ColumnResizeExpandModeDoc implements OnInit { +export class ColumnResizeExpandModeDoc { products!: Product[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/columnresizefitmodedoc.ts b/src/app/showcase/doc/table/columnresizefitmodedoc.ts index f86b8263231..d1a99c7db6c 100644 --- a/src/app/showcase/doc/table/columnresizefitmodedoc.ts +++ b/src/app/showcase/doc/table/columnresizefitmodedoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -8,35 +8,37 @@ import { ProductService } from '../../service/productservice'; template: `

Columns can be resized using drag drop by setting the resizableColumns to true. Fit mode is the default one and the overall table width does not change when a column is resized.

-
- - - - Code - Name - Category - Quantity - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ +
+ + + + Code + Name + Category + Quantity + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class ColumnResizeFitModeDoc implements OnInit { +export class ColumnResizeFitModeDoc { products!: Product[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/columnresizescrollablemodedoc.ts b/src/app/showcase/doc/table/columnresizescrollablemodedoc.ts index 7b66553e31f..9b41a32d585 100644 --- a/src/app/showcase/doc/table/columnresizescrollablemodedoc.ts +++ b/src/app/showcase/doc/table/columnresizescrollablemodedoc.ts @@ -1,39 +1,41 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Customer } from '../../domain/customer'; import { CustomerService } from '../../service/customerservice'; @Component({ selector: 'column-resize-scrollable-mode-doc', - template: `
- - - - Name - Country - Company - Representative - - - - - {{ customer.name }} - {{ customer.country.name }} - {{ customer.company }} - {{ customer.representative.name }} - - - -
+ template: ` +
+ + + + Name + Country + Company + Representative + + + + + {{ customer.name }} + {{ customer.country.name }} + {{ customer.company }} + {{ customer.representative.name }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class ColumnResizeScrollableModeDoc implements OnInit { +export class ColumnResizeScrollableModeDoc { customers!: Customer[]; constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersLarge().then((customers) => { this.customers = customers; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/columnselectiondoc.ts b/src/app/showcase/doc/table/columnselectiondoc.ts index 058b2f54c43..2b1e2fbfd90 100644 --- a/src/app/showcase/doc/table/columnselectiondoc.ts +++ b/src/app/showcase/doc/table/columnselectiondoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { MessageService } from 'primeng/api'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; @@ -9,6 +9,7 @@ import { ProductService } from '../../service/productservice'; template: `

Selection using custom elements.

+
@@ -34,18 +35,19 @@ import { ProductService } from '../../service/productservice';
+
`, changeDetection: ChangeDetectionStrategy.OnPush, providers: [MessageService] }) -export class ColumnSelectionDoc implements OnInit { +export class ColumnSelectionDoc { products!: Product[]; selectedProduct!: Product; constructor(private productService: ProductService, private messageService: MessageService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData(){ this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/columntoggledoc.ts b/src/app/showcase/doc/table/columntoggledoc.ts index 29ca9068014..595a7bd31f4 100644 --- a/src/app/showcase/doc/table/columntoggledoc.ts +++ b/src/app/showcase/doc/table/columntoggledoc.ts @@ -12,29 +12,31 @@ 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 }) @@ -47,7 +49,7 @@ export class ColumnToggleDoc { constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/contextmenudoc.ts b/src/app/showcase/doc/table/contextmenudoc.ts index 464c98d4a7a..a7ee92bad37 100644 --- a/src/app/showcase/doc/table/contextmenudoc.ts +++ b/src/app/showcase/doc/table/contextmenudoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { MenuItem, MessageService } from 'primeng/api'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; @@ -13,32 +13,34 @@ import { ProductService } from '../../service/productservice'; contextMenuSelection property is used to get a hold of the right clicked row. For dynamic columns, setting pContextMenuRowDisabled property as true disables context menu for that particular row.

-
- - - - - Code - Name - Category - Price - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.price | currency : 'USD' }} - - - -
+ +
+ + + + + Code + Name + Category + Price + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.price | currency : 'USD' }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush, providers: [MessageService] }) -export class ContextMenuDoc implements OnInit { +export class ContextMenuDoc { products!: Product[]; selectedProduct!: Product; @@ -47,7 +49,7 @@ export class ContextMenuDoc implements OnInit { constructor(private productService: ProductService, private messageService: MessageService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsSmall().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/controlledselectiondoc.ts b/src/app/showcase/doc/table/controlledselectiondoc.ts index db85ed9e5b5..c222793959b 100644 --- a/src/app/showcase/doc/table/controlledselectiondoc.ts +++ b/src/app/showcase/doc/table/controlledselectiondoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -8,36 +8,38 @@ import { ProductService } from '../../service/productservice'; template: `

Row selection can be controlled by utilizing rowSelectable and disabled properties.

-
- - - - - - - Code - Name - Category - Quantity - - - - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ +
+ + + + + + + Code + Name + Category + Quantity + + + + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class ControlledSelectionDoc implements OnInit { +export class ControlledSelectionDoc { products!: Product[]; selectedProducts!: Product; @@ -46,7 +48,7 @@ export class ControlledSelectionDoc implements OnInit { this.isRowSelectable = this.isRowSelectable.bind(this); } - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/customersdoc.ts b/src/app/showcase/doc/table/customersdoc.ts index 804e453d28a..3f632cd6311 100644 --- a/src/app/showcase/doc/table/customersdoc.ts +++ b/src/app/showcase/doc/table/customersdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Customer, Representative } from '../../domain/customer'; import { CustomerService } from '../../service/customerservice'; @@ -8,6 +8,7 @@ import { CustomerService } from '../../service/customerservice'; template: `

DataTable with selection, pagination, filtering, sorting and templating.

+
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class CustomersDoc implements OnInit { +export class CustomersDoc { customers!: Customer[]; selectedCustomers!: Customer[]; @@ -187,7 +189,7 @@ export class CustomersDoc implements OnInit { constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersLarge().then((customers) => { this.customers = customers; this.loading = false; diff --git a/src/app/showcase/doc/table/customsortdoc.ts b/src/app/showcase/doc/table/customsortdoc.ts index 15ebe3e39c7..456637c6ee0 100644 --- a/src/app/showcase/doc/table/customsortdoc.ts +++ b/src/app/showcase/doc/table/customsortdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { SortEvent } from 'primeng/api'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; @@ -12,6 +12,7 @@ import { ProductService } from '../../service/productservice'; sortField, sortOrder and multiSortMeta.

+
@@ -34,15 +35,16 @@ import { ProductService } from '../../service/productservice';
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class CustomSortDoc implements OnInit { +export class CustomSortDoc { products!: Product[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData(){ this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/dynamicdoc.ts b/src/app/showcase/doc/table/dynamicdoc.ts index 62af9fa8b54..e3cd8ded94e 100644 --- a/src/app/showcase/doc/table/dynamicdoc.ts +++ b/src/app/showcase/doc/table/dynamicdoc.ts @@ -12,6 +12,7 @@ interface Column { template: `

Columns can be defined dynamically using the *ngFor directive.

+
@@ -30,6 +31,7 @@ interface Column {
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -40,7 +42,7 @@ export class DynamicDoc { constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData(){ this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/expandablerowgroupdoc.ts b/src/app/showcase/doc/table/expandablerowgroupdoc.ts index 15fc5126e14..f053100861b 100644 --- a/src/app/showcase/doc/table/expandablerowgroupdoc.ts +++ b/src/app/showcase/doc/table/expandablerowgroupdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Customer } from '../../domain/customer'; import { CustomerService } from '../../service/customerservice'; @@ -8,63 +8,65 @@ import { CustomerService } from '../../service/customerservice'; template: `

When expandableRowGroups is present in subheader based row grouping, groups can be expanded and collapsed. State of the expansions are controlled using the expandedRows and onRowToggle properties.

-
- - - - Name - Country - Company - Status - Date - - - - - - - - {{ customer.representative.name }} - - - - - - Total Customers - {{ calculateCustomerTotal(customer.representative.name) }} - - - - - - {{ customer.name }} - - - - {{ customer.country.name }} - - - {{ customer.company }} - - - - - - {{ customer.date }} - - - - -
+ +
+ + + + Name + Country + Company + Status + Date + + + + + + + + {{ customer.representative.name }} + + + + + + Total Customers + {{ calculateCustomerTotal(customer.representative.name) }} + + + + + + {{ customer.name }} + + + + {{ customer.country.name }} + + + {{ customer.company }} + + + + + + {{ customer.date }} + + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class ExpandableRowGroupDoc implements OnInit { +export class ExpandableRowGroupDoc { customers!: Customer[]; constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersMedium().then((data) => { this.customers = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/exportdoc.ts b/src/app/showcase/doc/table/exportdoc.ts index 15fdcef8b42..e0b5919e441 100644 --- a/src/app/showcase/doc/table/exportdoc.ts +++ b/src/app/showcase/doc/table/exportdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import * as FileSaver from 'file-saver'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; @@ -24,36 +24,38 @@ interface ExportColumn {

PDF and EXCEL export are also available using 3rd party libraries such as jspdf. Example below demonstrates how to implement all three export options.

-
- - -
- - - - -
-
- - - - {{ col.header }} - - - - - - - {{ rowData[col.field] }} - - - -
-
+ +
+ + +
+ + + + +
+
+ + + + {{ col.header }} + + + + + + + {{ rowData[col.field] }} + + + +
+
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class ExportDoc implements OnInit { +export class ExportDoc { products!: Product[]; selectedProducts!: Product[]; @@ -64,7 +66,7 @@ export class ExportDoc implements OnInit { exportColumns!: ExportColumn[]; - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/filtermenudoc.ts b/src/app/showcase/doc/table/filtermenudoc.ts index 9c11e0580cc..dfce1f6426f 100644 --- a/src/app/showcase/doc/table/filtermenudoc.ts +++ b/src/app/showcase/doc/table/filtermenudoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit, ViewChild } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Table } from 'primeng/table'; import { Code } from '../../domain/code'; import { Customer, Representative } from '../../domain/customer'; @@ -9,6 +9,7 @@ import { CustomerService } from '../../service/customerservice'; template: `

Filters are displayed in an overlay.

+
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class FilterMenuDoc implements OnInit { +export class FilterMenuDoc { customers!: Customer[]; representatives!: Representative[]; @@ -168,7 +170,7 @@ export class FilterMenuDoc implements OnInit { constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData(){ this.customerService.getCustomersLarge().then((customers) => { this.customers = customers; this.loading = false; diff --git a/src/app/showcase/doc/table/filterrowdoc.ts b/src/app/showcase/doc/table/filterrowdoc.ts index 060d3e05795..217bc54521c 100644 --- a/src/app/showcase/doc/table/filterrowdoc.ts +++ b/src/app/showcase/doc/table/filterrowdoc.ts @@ -9,105 +9,107 @@ import { CustomerService } from '../../service/customerservice'; template: `

Filters are displayed inline within a separate row.

-
- - -
- - - - -
-
- - - Name - Country - Agent - Status - Verified - - - - - - - - - - - - - -
- - {{ option.name }} -
-
-
-
-
- - - - - - - - - - - - - - - - -
- - - - {{ customer.name }} - - - - {{ customer.country.name }} - - - - {{ customer.representative.name }} - - - - - - - - - - - - No customers found. - - -
-
+ +
+ + +
+ + + + +
+
+ + + Name + Country + Agent + Status + Verified + + + + + + + + + + + + + +
+ + {{ option.name }} +
+
+
+
+
+ + + + + + + + + + + + + + + + +
+ + + + {{ customer.name }} + + + + {{ customer.country.name }} + + + + {{ customer.representative.name }} + + + + + + + + + + + + No customers found. + + +
+
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class FilterRowDoc implements OnInit { +export class FilterRowDoc { customers!: Customer[]; representatives!: Representative[]; @@ -120,7 +122,7 @@ export class FilterRowDoc implements OnInit { constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersLarge().then((customers) => { this.customers = customers; this.loading = false; diff --git a/src/app/showcase/doc/table/flexiblescrolldoc.ts b/src/app/showcase/doc/table/flexiblescrolldoc.ts index d480dd4be55..df499a0bc10 100644 --- a/src/app/showcase/doc/table/flexiblescrolldoc.ts +++ b/src/app/showcase/doc/table/flexiblescrolldoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Customer } from '../../domain/customer'; import { CustomerService } from '../../service/customerservice'; @@ -11,6 +11,7 @@ import { CustomerService } from '../../service/customerservice'; viewport adjusts itself according to the size changes.

+
@@ -39,17 +40,18 @@ import { CustomerService } from '../../service/customerservice';
+ `, changeDetection: ChangeDetectionStrategy.OnPush }) -export class FlexibleScrollDoc implements OnInit { +export class FlexibleScrollDoc { customers!: Customer[]; dialogVisible: boolean = false; constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersMedium().then((data) => { this.customers = data; }); diff --git a/src/app/showcase/doc/table/frozencolumnsdoc.ts b/src/app/showcase/doc/table/frozencolumnsdoc.ts index e31c57ec2d9..5e2aee183be 100644 --- a/src/app/showcase/doc/table/frozencolumnsdoc.ts +++ b/src/app/showcase/doc/table/frozencolumnsdoc.ts @@ -8,49 +8,51 @@ import { CustomerService } from '../../service/customerservice'; template: `

Certain columns can be frozen by using the pFrozenColumn directive of the table component. In addition, alignFrozen is available to define whether the column should be fixed on the left or right.

-
- - - - - - Name - Id - Country - Date - Company - Status - Activity - Representative - Balance - - - - - {{ customer.name }} - {{ customer.id }} - {{ customer.country.name }} - {{ customer.date }} - {{ customer.company }} - {{ customer.status }} - {{ customer.activity }} - {{ customer.representative.name }} - {{ formatCurrency(customer.balance) }} - - - -
+ +
+ + + + + + Name + Id + Country + Date + Company + Status + Activity + Representative + Balance + + + + + {{ customer.name }} + {{ customer.id }} + {{ customer.country.name }} + {{ customer.date }} + {{ customer.company }} + {{ customer.status }} + {{ customer.activity }} + {{ customer.representative.name }} + {{ formatCurrency(customer.balance) }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class FrozenColumnsDoc implements OnInit { +export class FrozenColumnsDoc { balanceFrozen: boolean = false; customers!: Customer[]; constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersMedium().then((data) => { this.customers = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/frozenrowsdoc.ts b/src/app/showcase/doc/table/frozenrowsdoc.ts index 93909c51e75..bd473bcf91c 100644 --- a/src/app/showcase/doc/table/frozenrowsdoc.ts +++ b/src/app/showcase/doc/table/frozenrowsdoc.ts @@ -8,52 +8,54 @@ import { CustomerService } from '../../service/customerservice'; template: `

Frozen rows are used to fix certain rows while scrolling, this data is defined with the frozenValue property.

-
- - - - Name - Country - Company - Representative - - - - - - {{ customer.name }} - {{ customer.country.name }} - {{ customer.company }} - {{ customer.representative.name }} - - - - - - - - {{ customer.name }} - {{ customer.country.name }} - {{ customer.company }} - {{ customer.representative.name }} - - - - - - -
+ +
+ + + + Name + Country + Company + Representative + + + + + + {{ customer.name }} + {{ customer.country.name }} + {{ customer.company }} + {{ customer.representative.name }} + + + + + + + + {{ customer.name }} + {{ customer.country.name }} + {{ customer.company }} + {{ customer.representative.name }} + + + + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class FrozenRowsDoc implements OnInit { +export class FrozenRowsDoc { unlockedCustomers!: Customer[]; lockedCustomers!: Customer[]; constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersMedium().then((data) => { this.unlockedCustomers = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/gridlinesdoc.ts b/src/app/showcase/doc/table/gridlinesdoc.ts index 42280e85cde..cea6a97d548 100644 --- a/src/app/showcase/doc/table/gridlinesdoc.ts +++ b/src/app/showcase/doc/table/gridlinesdoc.ts @@ -8,28 +8,30 @@ import { ProductService } from '../../service/productservice'; template: `

Adding p-datatable-gridlines class displays grid lines.

-
- - Header - - - Code - Name - Category - Quantity - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - Footer - -
+ +
+ + Header + + + Code + Name + Category + Quantity + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + + Footer + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -38,7 +40,7 @@ export class GridlinesDoc { constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/horizontalandverticaldoc.ts b/src/app/showcase/doc/table/horizontalandverticaldoc.ts index 3295d2116a1..f0152d05df9 100644 --- a/src/app/showcase/doc/table/horizontalandverticaldoc.ts +++ b/src/app/showcase/doc/table/horizontalandverticaldoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Customer } from '../../domain/customer'; import { CustomerService } from '../../service/customerservice'; @@ -8,6 +8,7 @@ import { CustomerService } from '../../service/customerservice'; template: `

Horizontal and vertical scroll can be used together to enable double axis scrolling.

+
@@ -51,15 +52,16 @@ import { CustomerService } from '../../service/customerservice';
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class HorizontalAndVerticalScrollDoc implements OnInit { +export class HorizontalAndVerticalScrollDoc { customers!: Customer[]; constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersMedium().then((data) => { this.customers = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/lazyloaddoc.ts b/src/app/showcase/doc/table/lazyloaddoc.ts index a390dbb476b..75e5e32a85f 100644 --- a/src/app/showcase/doc/table/lazyloaddoc.ts +++ b/src/app/showcase/doc/table/lazyloaddoc.ts @@ -13,73 +13,75 @@ import { CustomerService } from '../../service/customerservice'; the next page or whether there are instant data changes, the selection array can be implemented in several ways. One of them is as in the example below.

-
- - - - - Name - Country - Company - Representative - - - - - - - - - - - - - - - - - - - -
- - {{ option.name }} -
-
-
-
-
- - -
- - - - - - {{ customer.name }} - {{ customer.country.name }} - {{ customer.company }} - {{ customer.representative.name }} - - -
-
+ +
+ + + + + Name + Country + Company + Representative + + + + + + + + + + + + + + + + + + + +
+ + {{ option.name }} +
+
+
+
+
+ + +
+ + + + + + {{ customer.name }} + {{ customer.country.name }} + {{ customer.company }} + {{ customer.representative.name }} + + +
+
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -99,6 +101,10 @@ export class LazyLoadDoc implements OnInit { constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} ngOnInit() { + this.loading = true; + } + + loadDemoData() { this.representatives = [ { name: 'Amy Elsner', image: 'amyelsner.png' }, { name: 'Anna Fali', image: 'annafali.png' }, @@ -111,8 +117,6 @@ export class LazyLoadDoc implements OnInit { { name: 'Stephen Shaw', image: 'stephenshaw.png' }, { name: 'Xuxue Feng', image: 'xuxuefeng.png' } ]; - - this.loading = true; } loadCustomers(event: LazyLoadEvent) { diff --git a/src/app/showcase/doc/table/multiplecolumnsortdoc.ts b/src/app/showcase/doc/table/multiplecolumnsortdoc.ts index 4572d26c4d1..6705fd59679 100644 --- a/src/app/showcase/doc/table/multiplecolumnsortdoc.ts +++ b/src/app/showcase/doc/table/multiplecolumnsortdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -9,38 +9,40 @@ import { ProductService } from '../../service/productservice';

Multiple columns can be sorted by defining sortMode as multiple. This mode requires metaKey (e.g. ⌘) to be pressed when clicking a header.

-
- - - - Code - Name - Category - Quantity - Price - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - {{ product.price | currency : 'USD' }} - - - -
+ +
+ + + + Code + Name + Category + Quantity + Price + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + {{ product.price | currency : 'USD' }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class MultipleColumnSortDoc implements OnInit { +export class MultipleColumnSortDoc { products: Product[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData(){ this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/multipleselectiondoc.ts b/src/app/showcase/doc/table/multipleselectiondoc.ts index c613c5dd485..5454951dd65 100644 --- a/src/app/showcase/doc/table/multipleselectiondoc.ts +++ b/src/app/showcase/doc/table/multipleselectiondoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -11,35 +11,37 @@ import { ProductService } from '../../service/productservice'; enables multiple selection without meta key.

-
-
- - MetaKey + +
+
+ + MetaKey +
+ + Multiple Selection with MetaKey + + + Code + Name + Category + Quantity + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + +
- - Multiple Selection with MetaKey - - - Code - Name - Category - Quantity - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ `, changeDetection: ChangeDetectionStrategy.OnPush }) -export class MultipleSelectionDoc implements OnInit { +export class MultipleSelectionDoc { products!: Product[]; selectedProducts!: Product; @@ -48,7 +50,7 @@ export class MultipleSelectionDoc implements OnInit { constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/pageonlyselectiondoc.ts b/src/app/showcase/doc/table/pageonlyselectiondoc.ts index 98ad9bb8046..e8f658eaa7b 100644 --- a/src/app/showcase/doc/table/pageonlyselectiondoc.ts +++ b/src/app/showcase/doc/table/pageonlyselectiondoc.ts @@ -5,43 +5,45 @@ import { ProductService } from '../../service/productservice'; @Component({ selector: 'page-only-selection-doc', - template: `
- - - - - - - Code - Name - Category - Quantity - - - - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ template: ` +
+ + + + + + + Code + Name + Category + Quantity + + + + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class PageOnlySelectionDoc implements OnInit { +export class PageOnlySelectionDoc { products!: Product[]; selectedProducts!: Product; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/paginatorbasicdoc.ts b/src/app/showcase/doc/table/paginatorbasicdoc.ts index df443d8c440..2b8a053aabd 100644 --- a/src/app/showcase/doc/table/paginatorbasicdoc.ts +++ b/src/app/showcase/doc/table/paginatorbasicdoc.ts @@ -11,40 +11,42 @@ import { CustomerService } from '../../service/customerservice'; lazy loading example.

-
- - - - Name - Country - Company - Representative - - - - - {{ customer.name }} - {{ customer.country.name }} - {{ customer.company }} - {{ customer.representative.name }} - - - - - - - - - -
+ +
+ + + + Name + Country + Company + Representative + + + + + {{ customer.name }} + {{ customer.country.name }} + {{ customer.company }} + {{ customer.representative.name }} + + + + + + + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -53,7 +55,7 @@ export class PaginatorBasicDoc { constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersLarge().then((customers) => { this.customers = customers; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/paginatorlocaledoc.ts b/src/app/showcase/doc/table/paginatorlocaledoc.ts index ead1766b188..b785093f45c 100644 --- a/src/app/showcase/doc/table/paginatorlocaledoc.ts +++ b/src/app/showcase/doc/table/paginatorlocaledoc.ts @@ -8,41 +8,43 @@ import { CustomerService } from '../../service/customerservice'; template: `

paginator localization information such as page numbers and rows per page options are defined with the paginatorLocale property which defaults to the user locale.

-
- - - - Name - Country - Company - Representative - - - - - {{ customer.name }} - {{ customer.country.name }} - {{ customer.company }} - {{ customer.representative.name }} - - - - - - - - - -
+ +
+ + + + Name + Country + Company + Representative + + + + + {{ customer.name }} + {{ customer.country.name }} + {{ customer.company }} + {{ customer.representative.name }} + + + + + + + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -51,7 +53,7 @@ export class PaginatorLocaleDoc { constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersLarge().then((customers) => { this.customers = customers; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/paginatorprogrammaticdoc.ts b/src/app/showcase/doc/table/paginatorprogrammaticdoc.ts index 62da8b17cdb..b847b0d003a 100644 --- a/src/app/showcase/doc/table/paginatorprogrammaticdoc.ts +++ b/src/app/showcase/doc/table/paginatorprogrammaticdoc.ts @@ -9,6 +9,7 @@ import { CustomerService } from '../../service/customerservice';

Paginator can also be controlled via model using a binding to the first property where changes trigger a pagination.

+
@@ -44,6 +45,7 @@ import { CustomerService } from '../../service/customerservice';
+ `, changeDetection: ChangeDetectionStrategy.OnPush @@ -57,7 +59,7 @@ export class PaginatorProgrammaticDoc { constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData(){ this.customerService.getCustomersLarge().then((customers) => { this.customers = customers; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/productsdoc.ts b/src/app/showcase/doc/table/productsdoc.ts index cf9aa6b96d1..b32ac269184 100644 --- a/src/app/showcase/doc/table/productsdoc.ts +++ b/src/app/showcase/doc/table/productsdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { ConfirmationService, MessageService } from 'primeng/api'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; @@ -9,152 +9,154 @@ import { ProductService } from '../../service/productservice'; template: `

CRUD implementation example with a Dialog.

-
- - - - - - + +
+ + + + + + + + + + + + + + + +
+
Manage Products
+ + + + +
+
+ + + + + + Name + Image + Price + Category + Reviews + Status + + + + + + + + + {{ product.name }} + + {{ product.price | currency : 'USD' }} + {{ product.category }} + + + + + + + + + + + +
In total there are {{ products ? products.length : 0 }} products.
+
+
+ + + + +
+ + + Name is required. +
+
+ + +
- - - - - - - - -
-
Manage Products
- - - - -
-
- - - - - - Name - Image - Price - Category - Reviews - Status - - - - - - - - - {{ product.name }} - - {{ product.price | currency : 'USD' }} - {{ product.category }} - - - - - - - - - - - -
In total there are {{ products ? products.length : 0 }} products.
-
-
- - - - -
- - - Name is required. -
-
- - -
- -
- - - - - - - - - -
- -
- -
-
- - -
-
- - -
-
- - -
-
- - -
+
+ + + + + + + + +
-
-
-
- - +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
-
- - + +
+
+ + +
+
+ + +
-
- + - - - - - + + + + + - -
+ +
+ `, changeDetection: ChangeDetectionStrategy.OnPush, providers: [MessageService, ConfirmationService] }) -export class ProductsDoc implements OnInit { +export class ProductsDoc { productDialog: boolean = false; products!: Product[]; @@ -169,7 +171,7 @@ export class ProductsDoc implements OnInit { constructor(private productService: ProductService, private messageService: MessageService, private confirmationService: ConfirmationService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProducts().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/radiobuttonselectiondoc.ts b/src/app/showcase/doc/table/radiobuttonselectiondoc.ts index 9b74b40711a..dccb0b788d8 100644 --- a/src/app/showcase/doc/table/radiobuttonselectiondoc.ts +++ b/src/app/showcase/doc/table/radiobuttonselectiondoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -8,41 +8,43 @@ import { ProductService } from '../../service/productservice'; template: `

Single selection can also be handled using radio buttons.

-
- - - - - Code - Name - Category - Quantity - - - - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ +
+ + + + + Code + Name + Category + Quantity + + + + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class RadioButtonSelectionDoc implements OnInit { +export class RadioButtonSelectionDoc { products!: Product[]; selectedProduct!: Product; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/reorderdoc.ts b/src/app/showcase/doc/table/reorderdoc.ts index 79a8e07760d..9c26405f5c6 100644 --- a/src/app/showcase/doc/table/reorderdoc.ts +++ b/src/app/showcase/doc/table/reorderdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -17,39 +17,41 @@ interface Column { reorder completes.

-
- - - - - - {{ col.header }} - - - - - - - - - - {{ rowData[col.field] }} - - - - -
+ +
+ + + + + + {{ col.header }} + + + + + + + + + + {{ rowData[col.field] }} + + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class ReorderDoc implements OnInit { +export class ReorderDoc { products!: Product[]; cols!: Column[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsSmall().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/responsivescrolldoc.ts b/src/app/showcase/doc/table/responsivescrolldoc.ts index 48687abdd63..356b4efee11 100644 --- a/src/app/showcase/doc/table/responsivescrolldoc.ts +++ b/src/app/showcase/doc/table/responsivescrolldoc.ts @@ -14,43 +14,45 @@ interface Column {

When there is not enough space for the table to fit all the content efficiently, table displays a horizontal scrollbar. It is suggested to give a min-width to the table to avoid design issues due wrapping of cell contents.

Following table displays a horizontal scrollbar when viewport is smaller than 50rem.

-
- - - - Name - Price - Category - Quantity - Status - Reviews - - - - - {{ product.name }} - {{ product.price | currency : 'USD' }} - {{ product.category }} - {{ product.quantity }} - - - - - - - -
+ +
+ + + + Name + Price + Category + Quantity + Status + Reviews + + + + + {{ product.name }} + {{ product.price | currency : 'USD' }} + {{ product.category }} + {{ product.quantity }} + + + + + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class ResponsiveScrollDoc implements OnInit { +export class ResponsiveScrollDoc { products!: Product[]; cols!: Column[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData(){ this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/responsivestackdoc.ts b/src/app/showcase/doc/table/responsivestackdoc.ts index e4e4196bd1e..1a0d2dda612 100644 --- a/src/app/showcase/doc/table/responsivestackdoc.ts +++ b/src/app/showcase/doc/table/responsivestackdoc.ts @@ -16,41 +16,43 @@ interface Column { p-column-title style class to the body cells.

-
- - - - Name - Price - Category - Quantity - Status - Reviews - - - - - Name{{ product.name }} - Price{{ product.price | currency : 'USD' }} - Category{{ product.category }} - Quantity{{ product.quantity }} - - Reviews - - - -
+ +
+ + + + Name + Price + Category + Quantity + Status + Reviews + + + + + Name{{ product.name }} + Price{{ product.price | currency : 'USD' }} + Category{{ product.category }} + Quantity{{ product.quantity }} + + Reviews + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class ResponsiveStackDoc implements OnInit { +export class ResponsiveStackDoc{ products!: Product[]; cols!: Column[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData(){ this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/roweditdoc.ts b/src/app/showcase/doc/table/roweditdoc.ts index b61a2e7faa2..82fb996497d 100644 --- a/src/app/showcase/doc/table/roweditdoc.ts +++ b/src/app/showcase/doc/table/roweditdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { MessageService, SelectItem } from 'primeng/api'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; @@ -21,76 +21,78 @@ import { ProductService } from '../../service/productservice'; whose key is the dataKey of the record where the value is any arbitrary number greater than zero.

-
- - - - - Code - Name - Inventory Status - Price - - - - - - - - - - - - {{ product.code }} - - - - - - - - - - {{ product.name }} - - - - - - - - - - {{ product.inventoryStatus }} - - - - - - - - - - {{ product.price | currency : 'USD' }} - - - - -
- - - -
- - -
-
-
+ +
+ + + + + Code + Name + Inventory Status + Price + + + + + + + + + + + + {{ product.code }} + + + + + + + + + + {{ product.name }} + + + + + + + + + + {{ product.inventoryStatus }} + + + + + + + + + + {{ product.price | currency : 'USD' }} + + + + +
+ + + +
+ + +
+
+
+
`, changeDetection: ChangeDetectionStrategy.OnPush, providers: [MessageService] }) -export class RowEditDoc implements OnInit { +export class RowEditDoc { products!: Product[]; statuses!: SelectItem[]; @@ -99,7 +101,7 @@ export class RowEditDoc implements OnInit { constructor(private productService: ProductService, private messageService: MessageService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/rowexpanddoc.ts b/src/app/showcase/doc/table/rowexpanddoc.ts index 474ef4c3380..2c06eedf5d8 100644 --- a/src/app/showcase/doc/table/rowexpanddoc.ts +++ b/src/app/showcase/doc/table/rowexpanddoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -12,6 +12,7 @@ import { ProductService } from '../../service/productservice'; event for the element.

+
@@ -79,15 +80,16 @@ import { ProductService } from '../../service/productservice';
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class RowExpandDoc implements OnInit { +export class RowExpandDoc { products!: Product[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsWithOrdersSmall().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/rowspangroupingdoc.ts b/src/app/showcase/doc/table/rowspangroupingdoc.ts index d21d5216966..6a919ca0d2b 100644 --- a/src/app/showcase/doc/table/rowspangroupingdoc.ts +++ b/src/app/showcase/doc/table/rowspangroupingdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Customer } from '../../domain/customer'; import { CustomerService } from '../../service/customerservice'; @@ -8,55 +8,57 @@ import { CustomerService } from '../../service/customerservice'; template: `

When rowGroupMode is configured to be rowspan, the grouping column spans multiple rows.

-
- - - - # - Representative - Name - Country - Company - Status - Date - - - - - {{ rowIndex }} - - - {{ customer.representative.name }} - - - {{ customer.name }} - - - - {{ customer.country.name }} - - - {{ customer.company }} - - - - - - {{ customer.date }} - - - - -
+ +
+ + + + # + Representative + Name + Country + Company + Status + Date + + + + + {{ rowIndex }} + + + {{ customer.representative.name }} + + + {{ customer.name }} + + + + {{ customer.country.name }} + + + {{ customer.company }} + + + + + + {{ customer.date }} + + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class RowspanGroupingDoc implements OnInit { +export class RowspanGroupingDoc { customers!: Customer[]; constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersMedium().then((data) => { this.customers = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/selectioneventsdoc.ts b/src/app/showcase/doc/table/selectioneventsdoc.ts index b24a25a9938..d96ca39eb50 100644 --- a/src/app/showcase/doc/table/selectioneventsdoc.ts +++ b/src/app/showcase/doc/table/selectioneventsdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { MessageService } from 'primeng/api'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; @@ -9,6 +9,7 @@ import { ProductService } from '../../service/productservice'; template: `

Table provides onRowSelect and onRowUnselect events to listen selection events.

+
@@ -30,18 +31,19 @@ import { ProductService } from '../../service/productservice';
+
`, changeDetection: ChangeDetectionStrategy.OnPush, providers: [MessageService] }) -export class SelectionEventsDoc implements OnInit { +export class SelectionEventsDoc { products!: Product[]; selectedProduct!: Product; constructor(private productService: ProductService, private messageService: MessageService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData(){ this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/singlecolumnsortdoc.ts b/src/app/showcase/doc/table/singlecolumnsortdoc.ts index aabda069fa0..7c89579e650 100644 --- a/src/app/showcase/doc/table/singlecolumnsortdoc.ts +++ b/src/app/showcase/doc/table/singlecolumnsortdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -12,6 +12,7 @@ import { ProductService } from '../../service/productservice';

Default sorting is executed on a single column, in order to enable multiple field sorting, set sortMode property to "multiple" and use metakey when clicking on another column.

+
@@ -34,15 +35,16 @@ import { ProductService } from '../../service/productservice';
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class SingleColumnSortDoc implements OnInit { +export class SingleColumnSortDoc { products!: Product[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData(){ this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/singleselectiondoc.ts b/src/app/showcase/doc/table/singleselectiondoc.ts index 170791b622a..ae0e9741aaf 100644 --- a/src/app/showcase/doc/table/singleselectiondoc.ts +++ b/src/app/showcase/doc/table/singleselectiondoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -15,37 +15,39 @@ import { ProductService } from '../../service/productservice'; setting it to false.

-
- - - - Code - Name - Category - Quantity - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ +
+ + + + Code + Name + Category + Quantity + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class SingleSelectionDoc implements OnInit { +export class SingleSelectionDoc { products!: Product[]; selectedProduct!: Product; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/sizedoc.ts b/src/app/showcase/doc/table/sizedoc.ts index f2cf54c2556..b828c9691fa 100644 --- a/src/app/showcase/doc/table/sizedoc.ts +++ b/src/app/showcase/doc/table/sizedoc.ts @@ -8,29 +8,31 @@ import { ProductService } from '../../service/productservice'; template: `

In addition to a regular table, alternatives with alternative sizes are available.

-
-
- + +
+
+ +
+ + + + Code + Name + Category + Quantity + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + +
- - - - Code - Name - Category - Quantity - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ `, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -43,7 +45,7 @@ export class SizeDoc { constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/statefuldoc.ts b/src/app/showcase/doc/table/statefuldoc.ts index 8c196c186a4..46ff3de6f62 100644 --- a/src/app/showcase/doc/table/statefuldoc.ts +++ b/src/app/showcase/doc/table/statefuldoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Customer } from '../../domain/customer'; import { CustomerService } from '../../service/customerservice'; @@ -12,6 +12,7 @@ import { CustomerService } from '../../service/customerservice'; browser is closed. Other alternative is local referring to localStorage for an extended lifetime.

+
@@ -65,17 +66,18 @@ import { CustomerService } from '../../service/customerservice';
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class StatefulDoc implements OnInit { +export class StatefulDoc { customers!: Customer[]; selectedCustomers!: Customer; constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersMini().then((data) => { this.customers = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/stripeddoc.ts b/src/app/showcase/doc/table/stripeddoc.ts index 2bcbb8f7d2e..173dd8b3920 100644 --- a/src/app/showcase/doc/table/stripeddoc.ts +++ b/src/app/showcase/doc/table/stripeddoc.ts @@ -8,26 +8,28 @@ import { ProductService } from '../../service/productservice'; template: `

Adding p-datatable-striped class displays striped rows.

-
- - - - Code - Name - Category - Quantity - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - {{ product.quantity }} - - - -
+ +
+ + + + Code + Name + Category + Quantity + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + {{ product.quantity }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -36,7 +38,7 @@ export class StripedDoc { constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/styledoc.ts b/src/app/showcase/doc/table/styledoc.ts index 55cf647938f..8155d893a46 100644 --- a/src/app/showcase/doc/table/styledoc.ts +++ b/src/app/showcase/doc/table/styledoc.ts @@ -8,30 +8,32 @@ import { ProductService } from '../../service/productservice'; template: `

Certain rows or cells can easily be styled based on conditions.

-
- - - - Code - Name - Category - Quantity - - - - - {{ product.code }} - {{ product.name }} - {{ product.category }} - -
- {{ product.quantity }} -
- - -
-
-
+ +
+ + + + Code + Name + Category + Quantity + + + + + {{ product.code }} + {{ product.name }} + {{ product.category }} + +
+ {{ product.quantity }} +
+ + +
+
+
+
`, changeDetection: ChangeDetectionStrategy.OnPush, styles: [ @@ -58,12 +60,12 @@ import { ProductService } from '../../service/productservice'; ` ] }) -export class StyleDoc implements OnInit { +export class StyleDoc { products!: Product[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/subheadergroupingdoc.ts b/src/app/showcase/doc/table/subheadergroupingdoc.ts index be2a4dea9dd..72d68b02d64 100644 --- a/src/app/showcase/doc/table/subheadergroupingdoc.ts +++ b/src/app/showcase/doc/table/subheadergroupingdoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Customer } from '../../domain/customer'; import { CustomerService } from '../../service/customerservice'; @@ -11,61 +11,63 @@ import { CustomerService } from '../../service/customerservice'; footer with groupfooter templates.

-
- - - - Name - Country - Company - Status - Date - - - - - - - {{ customer.representative.name }} - - - - - - Total Customers: {{ calculateCustomerTotal(customer.representative.name) }} - - - - - - {{ customer.name }} - - - - {{ customer.country.name }} - - - {{ customer.company }} - - - - - - {{ customer.date }} - - - - -
+ +
+ + + + Name + Country + Company + Status + Date + + + + + + + {{ customer.representative.name }} + + + + + + Total Customers: {{ calculateCustomerTotal(customer.representative.name) }} + + + + + + {{ customer.name }} + + + + {{ customer.country.name }} + + + {{ customer.company }} + + + + + + {{ customer.date }} + + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class SubheaderGroupingDoc implements OnInit { +export class SubheaderGroupingDoc { customers!: Customer[]; constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersMedium().then((data) => { this.customers = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/tabledoc.module.ts b/src/app/showcase/doc/table/tabledoc.module.ts index 2f8439f32f0..36925424477 100644 --- a/src/app/showcase/doc/table/tabledoc.module.ts +++ b/src/app/showcase/doc/table/tabledoc.module.ts @@ -81,7 +81,7 @@ import { StylingDoc } from './stylingdoc'; import { SelectionEventsDoc } from './selectioneventsdoc'; import { AccessibilityDoc } from './accessibilitydoc'; import { PaginatorLocaleDoc } from './paginatorlocaledoc'; - +import { DeferredDemoModule } from 'primeng/demo'; @NgModule({ imports: [ CommonModule, @@ -112,7 +112,8 @@ import { PaginatorLocaleDoc } from './paginatorlocaledoc'; SkeletonModule, SelectButtonModule, AppCodeModule, - AppDocModule + AppDocModule, + DeferredDemoModule ], declarations: [ ImportDoc, diff --git a/src/app/showcase/doc/table/templatedoc.ts b/src/app/showcase/doc/table/templatedoc.ts index eb84559c35a..8200e98ad42 100644 --- a/src/app/showcase/doc/table/templatedoc.ts +++ b/src/app/showcase/doc/table/templatedoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Product } from '../../domain/product'; import { ProductService } from '../../service/productservice'; @@ -13,52 +13,54 @@ interface Column { template: `

Custom content at header, body and footer sections are supported via templating.

-
- - -
- Products - -
-
- - - Name - Image - Price - Category - Reviews - Status - - - - - {{ product.name }} - - {{ product.price | currency : 'USD' }} - {{ product.category }} - - - - - - - -
In total there are {{ products ? products.length : 0 }} products.
-
-
-
+ +
+ + +
+ Products + +
+
+ + + Name + Image + Price + Category + Reviews + Status + + + + + {{ product.name }} + + {{ product.price | currency : 'USD' }} + {{ product.category }} + + + + + + + +
In total there are {{ products ? products.length : 0 }} products.
+
+
+
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class TemplateDoc implements OnInit { +export class TemplateDoc { products!: Product[]; cols!: Column[]; constructor(private productService: ProductService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.productService.getProductsMini().then((data) => { this.products = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/verticalscrolldoc.ts b/src/app/showcase/doc/table/verticalscrolldoc.ts index 263b50de847..58659e26fa0 100644 --- a/src/app/showcase/doc/table/verticalscrolldoc.ts +++ b/src/app/showcase/doc/table/verticalscrolldoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core'; import { Code } from '../../domain/code'; import { Customer } from '../../domain/customer'; import { CustomerService } from '../../service/customerservice'; @@ -8,35 +8,37 @@ import { CustomerService } from '../../service/customerservice'; template: `

Adding scrollable property along with a scrollHeight for the data viewport enables vertical scrolling with fixed headers.

-
- - - - Name - Country - Company - Representative - - - - - {{ customer.name }} - {{ customer.country.name }} - {{ customer.company }} - {{ customer.representative.name }} - - - -
+ +
+ + + + Name + Country + Company + Representative + + + + + {{ customer.name }} + {{ customer.country.name }} + {{ customer.company }} + {{ customer.representative.name }} + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class VerticalScrollDoc implements OnInit { +export class VerticalScrollDoc { customers!: Customer[]; constructor(private customerService: CustomerService, private cd: ChangeDetectorRef) {} - ngOnInit() { + loadDemoData() { this.customerService.getCustomersMedium().then((data) => { this.customers = data; this.cd.markForCheck(); diff --git a/src/app/showcase/doc/table/virtualscrolldoc.ts b/src/app/showcase/doc/table/virtualscrolldoc.ts index 495559cc579..3bbb1c6f04c 100644 --- a/src/app/showcase/doc/table/virtualscrolldoc.ts +++ b/src/app/showcase/doc/table/virtualscrolldoc.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component } from '@angular/core'; import { Car } from '../../domain/car'; import { Code } from '../../domain/code'; import { CarService } from '../../service/carservice'; @@ -16,6 +16,7 @@ interface Column { suggested to use the same virtualScrollItemSize value on the tr element inside the body template.

+
@@ -34,10 +35,11 @@ interface Column {
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class VirtualScrollDoc implements OnInit { +export class VirtualScrollDoc { cars!: Car[]; virtualCars!: Car[]; @@ -46,7 +48,7 @@ export class VirtualScrollDoc implements OnInit { constructor(private carService: CarService) {} - ngOnInit() { + loadDemoData() { this.cols = [ { field: 'id', header: 'Id' }, { field: 'vin', header: 'Vin' }, diff --git a/src/app/showcase/doc/table/virtualscrolllazydoc.ts b/src/app/showcase/doc/table/virtualscrolllazydoc.ts index 7fdc9c34a56..e24c8847528 100644 --- a/src/app/showcase/doc/table/virtualscrolllazydoc.ts +++ b/src/app/showcase/doc/table/virtualscrolllazydoc.ts @@ -17,35 +17,37 @@ interface Column { suggested to use the same virtualScrollItemSize value on the tr element inside the body template.

-
- - - - - {{ col.header }} - - - - - - - {{ rowData[col.field] }} - - - - - - - - - - - -
+ +
+ + + + + {{ col.header }} + + + + + + + {{ rowData[col.field] }} + + + + + + + + + + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) -export class VirtualScrollLazyDoc implements OnInit { +export class VirtualScrollLazyDoc { cars!: Car[]; virtualCars!: Car[]; @@ -54,7 +56,7 @@ export class VirtualScrollLazyDoc implements OnInit { constructor(private carService: CarService) {} - ngOnInit() { + loadDemoData() { this.cols = [ { field: 'id', header: 'Id' }, { field: 'vin', header: 'Vin' }, From 4b49e6b6c1326719e09d2034c8442f556be3b7d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87etin?= <69278826+cetincakiroglu@users.noreply.github.com> Date: Thu, 4 Jan 2024 10:29:13 +0300 Subject: [PATCH 2/3] Update structure --- src/app/components/demo/ng-package.json | 6 ------ src/app/components/demo/public_api.ts | 1 - .../demo/deferreddemo.scss} | 0 .../demo/deferreddemo.ts | 17 ++++------------- src/app/showcase/doc/table/tabledoc.module.ts | 5 +++-- 5 files changed, 7 insertions(+), 22 deletions(-) delete mode 100644 src/app/components/demo/ng-package.json delete mode 100644 src/app/components/demo/public_api.ts rename src/app/{components/demo/deferreddemo.css => showcase/demo/deferreddemo.scss} (100%) rename src/app/{components => showcase}/demo/deferreddemo.ts (77%) diff --git a/src/app/components/demo/ng-package.json b/src/app/components/demo/ng-package.json deleted file mode 100644 index ab5467eb7e4..00000000000 --- a/src/app/components/demo/ng-package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "ng-packagr/ng-package.schema.json", - "lib": { - "entryFile": "public_api.ts" - } - } \ No newline at end of file diff --git a/src/app/components/demo/public_api.ts b/src/app/components/demo/public_api.ts deleted file mode 100644 index 75d9b10f247..00000000000 --- a/src/app/components/demo/public_api.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './deferreddemo'; diff --git a/src/app/components/demo/deferreddemo.css b/src/app/showcase/demo/deferreddemo.scss similarity index 100% rename from src/app/components/demo/deferreddemo.css rename to src/app/showcase/demo/deferreddemo.scss diff --git a/src/app/components/demo/deferreddemo.ts b/src/app/showcase/demo/deferreddemo.ts similarity index 77% rename from src/app/components/demo/deferreddemo.ts rename to src/app/showcase/demo/deferreddemo.ts index e8b1cfb3e48..45694fa6f3e 100755 --- a/src/app/components/demo/deferreddemo.ts +++ b/src/app/showcase/demo/deferreddemo.ts @@ -1,19 +1,17 @@ import { CommonModule, isPlatformBrowser } from '@angular/common'; -import { Component, ElementRef, EventEmitter, Inject, Input, NgModule, OnInit, Output, PLATFORM_ID } from '@angular/core'; -import { SharedModule } from 'primeng/api'; +import { Component, ElementRef, EventEmitter, Inject, Input, OnInit, Output, PLATFORM_ID } from '@angular/core'; @Component({ selector: 'p-deferred-demo', + standalone: true, + imports: [CommonModule], template: `
Loading...
`, - styleUrls: ['./deferreddemo.css'], - host: { - class: 'p-element' - } + styleUrl: './deferreddemo.scss' }) export class DeferredDemo implements OnInit { visible: boolean = false; @@ -52,10 +50,3 @@ export class DeferredDemo implements OnInit { clearTimeout(this.timeout); } } - -@NgModule({ - imports: [CommonModule, SharedModule], - exports: [DeferredDemo, SharedModule], - declarations: [DeferredDemo] -}) -export class DeferredDemoModule {} diff --git a/src/app/showcase/doc/table/tabledoc.module.ts b/src/app/showcase/doc/table/tabledoc.module.ts index 36925424477..5bc4c656249 100644 --- a/src/app/showcase/doc/table/tabledoc.module.ts +++ b/src/app/showcase/doc/table/tabledoc.module.ts @@ -81,7 +81,8 @@ import { StylingDoc } from './stylingdoc'; import { SelectionEventsDoc } from './selectioneventsdoc'; import { AccessibilityDoc } from './accessibilitydoc'; import { PaginatorLocaleDoc } from './paginatorlocaledoc'; -import { DeferredDemoModule } from 'primeng/demo'; +import { DeferredDemo } from '../../demo/deferreddemo'; + @NgModule({ imports: [ CommonModule, @@ -113,7 +114,7 @@ import { DeferredDemoModule } from 'primeng/demo'; SelectButtonModule, AppCodeModule, AppDocModule, - DeferredDemoModule + DeferredDemo ], declarations: [ ImportDoc, From 30507a3208ca74d9c5d0d8b61567f747dbdd8d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87etin?= <69278826+cetincakiroglu@users.noreply.github.com> Date: Thu, 4 Jan 2024 10:46:53 +0300 Subject: [PATCH 3/3] Refactor --- src/app/showcase/demo/deferreddemo.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/app/showcase/demo/deferreddemo.ts b/src/app/showcase/demo/deferreddemo.ts index 45694fa6f3e..c4f76e9fbc6 100755 --- a/src/app/showcase/demo/deferreddemo.ts +++ b/src/app/showcase/demo/deferreddemo.ts @@ -6,10 +6,11 @@ import { Component, ElementRef, EventEmitter, Inject, Input, OnInit, Output, PLA standalone: true, imports: [CommonModule], template: ` -
Loading...
- - - + @if(!visible){ +
Loading...
+ } @else { + + } `, styleUrl: './deferreddemo.scss' }) @@ -43,6 +44,7 @@ export class DeferredDemo implements OnInit { this.observer.observe(this.el.nativeElement); } } + ngOnDestroy() { if (!this.visible && this.el.nativeElement) { this.observer?.unobserve(this.el.nativeElement);