Skip to content

Commit

Permalink
fix(table): fix a bug where source changes and pager doesn't get upda…
Browse files Browse the repository at this point in the history
…ted (#329)
  • Loading branch information
Deilan authored and lexzhukov committed Apr 28, 2017
1 parent f5496e0 commit 086cd1f
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/ng2-smart-table/components/pager/pager.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';

import { DataSource } from '../../lib/data-source/data-source';

Expand Down Expand Up @@ -35,7 +36,7 @@ import { DataSource } from '../../lib/data-source/data-source';
</nav>
`,
})
export class PagerComponent implements OnInit {
export class PagerComponent implements OnChanges {

@Input() source: DataSource;

Expand All @@ -46,19 +47,25 @@ export class PagerComponent implements OnInit {
protected count: number = 0;
protected perPage: number;

protected dataChangedSub: Subscription;

ngOnInit() {
this.source.onChanged().subscribe((changes) => {
this.page = this.source.getPaging().page;
this.perPage = this.source.getPaging().perPage;
this.count = this.source.count();
if (this.isPageOutOfBounce()) {
this.source.setPage(--this.page);
ngOnChanges(changes: SimpleChanges) {
if (changes.source) {
if (!changes.source.firstChange) {
this.dataChangedSub.unsubscribe();
}

this.processPageChange(changes);
this.initPages();
});
this.dataChangedSub = this.source.onChanged().subscribe((dataChanges) => {
this.page = this.source.getPaging().page;
this.perPage = this.source.getPaging().perPage;
this.count = this.source.count();
if (this.isPageOutOfBounce()) {
this.source.setPage(--this.page);
}

this.processPageChange(dataChanges);
this.initPages();
});
}
}

/**
Expand Down

0 comments on commit 086cd1f

Please sign in to comment.