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)); + } }