Skip to content

Commit

Permalink
feat(module:table): add nzIsPageIndexReset option (#348) (#359)
Browse files Browse the repository at this point in the history
close #348
  • Loading branch information
alche47 authored and vthinkxie committed Sep 23, 2017
1 parent 10989ae commit 60e3da9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/components/table/nz-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;

@ContentChildren(NzThDirective, { descendants: true })
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions src/showcase/nz-demo-table/nz-demo-table.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<article>
<article>

<section class="markdown">
<h1>Table 表格</h1>
Expand Down Expand Up @@ -290,7 +290,12 @@ <h3><span>nz-table</span>
<td>Boolean</td>
<td>false</td>
</tr>

<tr>
<td>nzIsPageIndexReset</td>
<td>数据变更后是否保留在数据变更前的页码</td>
<td>Boolean</td>
<td>true</td>
</tr>
</tbody>
</table>
<h3><span>nz-table-sort</span>
Expand Down

0 comments on commit 60e3da9

Please sign in to comment.