From 60e3da932ab8c7121816f27ab6914e9f03cca8cb Mon Sep 17 00:00:00 2001 From: Alche Date: Sat, 23 Sep 2017 20:11:10 +0800 Subject: [PATCH] feat(module:table): add nzIsPageIndexReset option (#348) (#359) close #348 --- src/components/table/nz-table.component.ts | 8 +++++++- src/showcase/nz-demo-table/nz-demo-table.html | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/table/nz-table.component.ts b/src/components/table/nz-table.component.ts index 45dcf579f65..e5fdf95d244 100644 --- a/src/components/table/nz-table.component.ts +++ b/src/components/table/nz-table.component.ts @@ -111,6 +111,7 @@ export class NzTableComponent implements AfterViewInit, OnInit { @Input() nzShowTotal = false; @Input() nzShowFooter = false; @Input() nzShowTitle = false; + @Input() nzIsPageIndexReset = true; @ContentChild('nzFixedHeader') fixedHeader: TemplateRef; @ContentChildren(NzThDirective, { descendants: true }) @@ -201,7 +202,12 @@ export class NzTableComponent implements AfterViewInit, OnInit { if (!this._isAjax) { if (this.nzIsPagination) { if (forceRefresh) { - this.nzPageIndex = 1; + if (this.nzIsPageIndexReset) { + this.nzPageIndex = 1; + } else { + const maxPageIndex = Math.ceil(this._dataSet.length / this.nzPageSize); + this.nzPageIndex = this.nzPageIndex > maxPageIndex ? maxPageIndex : this.nzPageIndex; + } } this.data = this._dataSet.slice((this.nzPageIndex - 1) * this.nzPageSize, this.nzPageIndex * this.nzPageSize); } else { diff --git a/src/showcase/nz-demo-table/nz-demo-table.html b/src/showcase/nz-demo-table/nz-demo-table.html index b6840f74c31..f027d3681ab 100644 --- a/src/showcase/nz-demo-table/nz-demo-table.html +++ b/src/showcase/nz-demo-table/nz-demo-table.html @@ -1,4 +1,4 @@ -
+

Table 表格

@@ -290,7 +290,12 @@

nz-table Boolean false - + + nzIsPageIndexReset + 数据变更后是否保留在数据变更前的页码 + Boolean + true +

nz-table-sort