Skip to content

Commit cd22c05

Browse files
committed
docs(examples): migrate content-full-layout-full-scroll example to signals
1 parent b34955c commit cd22c05

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

src/app/examples/si-layouts/content-full-layout-full-scroll.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h1 class="application-name">Application name</h1>
5555
columnMode="force"
5656
selectionType="single"
5757
[cssClasses]="tableConfig.cssClasses"
58-
[rows]="rows"
58+
[rows]="rows()"
5959
[columns]="[
6060
{ name: 'Name', sortable: false },
6161
{ name: 'Role', sortable: false },
@@ -65,10 +65,10 @@ <h1 class="application-name">Application name</h1>
6565
[footerHeight]="tableConfig.footerHeight"
6666
[rowHeight]="tableConfig.rowHeightSmall"
6767
[externalPaging]="true"
68-
[count]="page.totalElements"
69-
[offset]="page.pageNumber"
70-
[limit]="page.size"
71-
[ghostLoadingIndicator]="isLoading > 0"
68+
[count]="totalElements()"
69+
[offset]="pageNumber()"
70+
[limit]="pageSize()"
71+
[ghostLoadingIndicator]="isLoading() > 0"
7272
(page)="setPage($event)"
7373
(siResizeObserver)="updateTableData($event)"
7474
>
@@ -78,8 +78,8 @@ <h1 class="application-name">Application name</h1>
7878
class="ms-auto"
7979
forwardButtonText="forward"
8080
backButtonText="back"
81-
[currentPage]="page.pageNumber + 1"
82-
[totalRowCount]="rows.length"
81+
[currentPage]="pageNumber() + 1"
82+
[totalRowCount]="rows().length"
8383
(currentPageChange)="table.onFooterPage({ page: $event })"
8484
/>
8585
</ng-template>

src/app/examples/si-layouts/content-full-layout-full-scroll.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Siemens 2016 - 2025
33
* SPDX-License-Identifier: MIT
44
*/
5-
import { Component, inject, OnInit } from '@angular/core';
5+
import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core';
66
import { RouterLink } from '@angular/router';
77
import {
88
SiAccountDetailsComponent,
@@ -47,10 +47,13 @@ import { CorporateEmployee, DataService, Page, PageRequest } from '../datatable/
4747
SiHeaderLogoDirective
4848
],
4949
templateUrl: './content-full-layout-full-scroll.html',
50-
providers: [DataService]
50+
providers: [DataService],
51+
changeDetection: ChangeDetectionStrategy.OnPush
5152
})
5253
export class SampleComponent implements OnInit {
53-
menuItems: NavbarVerticalItem[] = [
54+
private readonly dataService = inject(DataService);
55+
protected readonly tableConfig = SI_DATATABLE_CONFIG;
56+
protected readonly menuItems: NavbarVerticalItem[] = [
5457
{
5558
type: 'group',
5659
label: 'Home',
@@ -73,13 +76,13 @@ export class SampleComponent implements OnInit {
7376
{ type: 'router-link', label: 'Energy & Operations', routerLink: 'energy' },
7477
{ type: 'router-link', label: 'Test Coverage', routerLink: 'coverage' }
7578
];
76-
tableConfig = SI_DATATABLE_CONFIG;
77-
pageRequest?: PageRequest;
78-
page = new Page();
79-
rows = new Array<CorporateEmployee>();
80-
isLoading = 0;
8179

82-
private dataService = inject(DataService);
80+
protected pageRequest?: PageRequest;
81+
protected readonly totalElements = signal(0);
82+
protected readonly pageNumber = signal(0);
83+
protected readonly pageSize = signal(0);
84+
protected readonly rows = signal<CorporateEmployee[]>([]);
85+
protected readonly isLoading = signal(0);
8386

8487
ngOnInit(): void {
8588
// timeout needed to work in the iFrame in the docs
@@ -96,21 +99,23 @@ export class SampleComponent implements OnInit {
9699
this.pageRequest?.pageSize !== pageRequest.pageSize
97100
) {
98101
this.pageRequest = pageRequest;
99-
this.isLoading++;
102+
this.isLoading.update(value => value + 1);
100103
// We reload the data when the page number or page size changes.
101104
// During this time, we want to show the ghost loading indicator.
102105
// To make sure no data is presented. We set the rows in the table
103106
// to an empty array.
104-
this.rows = [];
107+
this.rows.set([]);
105108
this.dataService.getResults(pageRequest).subscribe(pagedData => {
106-
this.isLoading--;
109+
this.isLoading.update(value => value - 1);
107110
// Make sure we set the date to the latest page request.
108111
if (
109112
this.pageRequest?.offset === pageRequest.offset &&
110113
this.pageRequest?.pageSize === pageRequest.pageSize
111114
) {
112-
this.page = pagedData.page;
113-
this.rows = pagedData.data;
115+
this.totalElements.set(pagedData.page.totalElements);
116+
this.pageNumber.set(pagedData.page.pageNumber);
117+
this.pageSize.set(pagedData.page.size);
118+
this.rows.set(pagedData.data);
114119
}
115120
});
116121
}
@@ -124,10 +129,10 @@ export class SampleComponent implements OnInit {
124129
const bodyHeight =
125130
dimensions.height - SI_DATATABLE_CONFIG.headerHeight - SI_DATATABLE_CONFIG.footerHeight;
126131
const pageSize = Math.floor(bodyHeight / SI_DATATABLE_CONFIG.rowHeightSmall);
127-
this.page.size = pageSize;
132+
this.pageSize.set(pageSize);
128133
this.setPage({
129-
offset: this.page.pageNumber,
130-
pageSize: this.page.size
134+
offset: this.pageNumber(),
135+
pageSize: this.pageSize()
131136
});
132137
}
133138
}

0 commit comments

Comments
 (0)