Skip to content

Commit 60e3da9

Browse files
alchexievthinkxie
authored andcommitted
feat(module:table): add nzIsPageIndexReset option (#348) (#359)
close #348
1 parent 10989ae commit 60e3da9

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/components/table/nz-table.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class NzTableComponent implements AfterViewInit, OnInit {
111111
@Input() nzShowTotal = false;
112112
@Input() nzShowFooter = false;
113113
@Input() nzShowTitle = false;
114+
@Input() nzIsPageIndexReset = true;
114115
@ContentChild('nzFixedHeader') fixedHeader: TemplateRef<any>;
115116

116117
@ContentChildren(NzThDirective, { descendants: true })
@@ -201,7 +202,12 @@ export class NzTableComponent implements AfterViewInit, OnInit {
201202
if (!this._isAjax) {
202203
if (this.nzIsPagination) {
203204
if (forceRefresh) {
204-
this.nzPageIndex = 1;
205+
if (this.nzIsPageIndexReset) {
206+
this.nzPageIndex = 1;
207+
} else {
208+
const maxPageIndex = Math.ceil(this._dataSet.length / this.nzPageSize);
209+
this.nzPageIndex = this.nzPageIndex > maxPageIndex ? maxPageIndex : this.nzPageIndex;
210+
}
205211
}
206212
this.data = this._dataSet.slice((this.nzPageIndex - 1) * this.nzPageSize, this.nzPageIndex * this.nzPageSize);
207213
} else {

src/showcase/nz-demo-table/nz-demo-table.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<article>
1+
<article>
22

33
<section class="markdown">
44
<h1>Table 表格</h1>
@@ -290,7 +290,12 @@ <h3><span>nz-table</span>
290290
<td>Boolean</td>
291291
<td>false</td>
292292
</tr>
293-
293+
<tr>
294+
<td>nzIsPageIndexReset</td>
295+
<td>数据变更后是否保留在数据变更前的页码</td>
296+
<td>Boolean</td>
297+
<td>true</td>
298+
</tr>
294299
</tbody>
295300
</table>
296301
<h3><span>nz-table-sort</span>

0 commit comments

Comments
 (0)