Skip to content

Commit

Permalink
Refactored #5303 fix with a setter
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici authored and Çağatay Çivici committed Mar 26, 2018
1 parent 2a1fc0f commit 35f0aa1
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ export class Table implements OnInit, AfterContentInit {

@Input() first: number = 0;

@Input() totalRecords: number = 0;

@Input() pageLinks: number = 5;

@Input() rowsPerPageOptions: number[];
Expand Down Expand Up @@ -245,6 +243,8 @@ export class Table implements OnInit, AfterContentInit {

_value: any[] = [];

_totalRecords: number = 0;

filteredValue: any[];

headerTemplate: TemplateRef<any>;
Expand Down Expand Up @@ -401,9 +401,10 @@ export class Table implements OnInit, AfterContentInit {
}
set value(val: any[]) {
this._value = val;
this.updateTotalRecords();


if (!this.lazy) {
this.totalRecords = (this._value ? this._value.length : 0);

if (this.sortMode == 'single')
this.sortSingle();
else if (this.sortMode == 'multiple')
Expand All @@ -417,6 +418,14 @@ export class Table implements OnInit, AfterContentInit {
this.tableService.onValueChange(val);
}

@Input() get totalRecords(): number {
return this._totalRecords;
}
set totalRecords(val: number) {
this._totalRecords = val;
this.tableService.onTotalRecordsChange(this._totalRecords);
}

@Input() get sortField(): string {
return this._sortField;
}
Expand Down Expand Up @@ -485,12 +494,6 @@ export class Table implements OnInit, AfterContentInit {
}
}

updateTotalRecords() {
this.totalRecords = this.lazy ? this.totalRecords : (this._value ? this._value.length : 0);

this.tableService.onTotalRecordsChange(this.totalRecords);
}

onPageChange(event) {
this.first = event.first;
this.rows = event.rows;
Expand Down Expand Up @@ -1220,11 +1223,13 @@ export class Table implements OnInit, AfterContentInit {
this.filters = {};

this.first = 0;
this.updateTotalRecords();

if(this.lazy) {
this.onLazyLoad.emit(this.createLazyLoadMetadata());
}
else {
this.totalRecords = (this._value ? this._value.length : 0);
}
}

public exportCSV(options?: any) {
Expand Down Expand Up @@ -1880,7 +1885,9 @@ export class ScrollableView implements AfterViewInit,OnDestroy {
}

setVirtualScrollerHeight() {
this.virtualScrollerViewChild.nativeElement.style.height = this.dt.totalRecords * this.dt.virtualRowHeight + 'px';
if(this.virtualScrollerViewChild.nativeElement) {
this.virtualScrollerViewChild.nativeElement.style.height = this.dt.totalRecords * this.dt.virtualRowHeight + 'px';
}
}

hasVerticalOverflow() {
Expand Down

0 comments on commit 35f0aa1

Please sign in to comment.