From d42de0545cbf50679d03d761933273ec1cd6e597 Mon Sep 17 00:00:00 2001 From: Vladimir Potekhin Date: Thu, 12 Dec 2024 19:16:40 +0300 Subject: [PATCH] fix(addon-table): fix calculating start page --- .../table-pagination/table-pagination.component.ts | 2 +- .../demo/src/modules/components/table-pagination/index.html | 1 + .../demo/src/modules/components/table-pagination/index.ts | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/projects/addon-table/components/table-pagination/table-pagination.component.ts b/projects/addon-table/components/table-pagination/table-pagination.component.ts index c407eb2fbfdc..bf7239d0314b 100644 --- a/projects/addon-table/components/table-pagination/table-pagination.component.ts +++ b/projects/addon-table/components/table-pagination/table-pagination.component.ts @@ -90,7 +90,7 @@ export class TuiTablePagination { } protected get start(): number { - return this.page * this.size; + return Math.min(this.page * this.size, Math.max(this.total - this.size, 0)); } protected get end(): number { diff --git a/projects/demo/src/modules/components/table-pagination/index.html b/projects/demo/src/modules/components/table-pagination/index.html index 746614bc7c0d..576d6d9ec005 100644 --- a/projects/demo/src/modules/components/table-pagination/index.html +++ b/projects/demo/src/modules/components/table-pagination/index.html @@ -59,6 +59,7 @@ documentationPropertyName="total" documentationPropertyType="number" [(documentationPropertyValue)]="total" + (documentationPropertyValueChange)="totalChange($event)" > Total amount of items/lines in the table. diff --git a/projects/demo/src/modules/components/table-pagination/index.ts b/projects/demo/src/modules/components/table-pagination/index.ts index 358bcae20497..c614458f0181 100644 --- a/projects/demo/src/modules/components/table-pagination/index.ts +++ b/projects/demo/src/modules/components/table-pagination/index.ts @@ -27,4 +27,9 @@ export default class Page { this.page = page; this.size = size; } + + protected totalChange(total: number): void { + this.total = total; + this.size = Math.min(this.size, Math.max(total, 1)); + } }