Skip to content

Commit

Permalink
Better fixes #5485
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici authored and Çağatay Çivici committed Aug 14, 2018
1 parent 7c938f0 commit f29be5a
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export class TableService {
private contextMenuSource = new Subject<any>();
private valueSource = new Subject<any>();
private totalRecordsSource = new Subject<any>();
private columnsSource = new Subject();

sortSource$ = this.sortSource.asObservable();
selectionSource$ = this.selectionSource.asObservable();
contextMenuSource$ = this.contextMenuSource.asObservable();
valueSource$ = this.valueSource.asObservable();
totalRecordsSource$ = this.totalRecordsSource.asObservable();
columnsSource$ = this.columnsSource.asObservable();

onSort(sortMeta: SortMeta|SortMeta[]) {
this.sortSource.next(sortMeta);
Expand All @@ -45,6 +47,10 @@ export class TableService {
onTotalRecordsChange(value: number) {
this.totalRecordsSource.next(value);
}

onColumnsChange(columns: any[]) {
this.columnsSource.next(columns);
}
}

@Component({
Expand Down Expand Up @@ -100,8 +106,6 @@ export class TableService {
})
export class Table implements OnInit, AfterContentInit, BlockableUI {

@Input() columns: any[];

@Input() frozenColumns: any[];

@Input() frozenValue: any[];
Expand Down Expand Up @@ -252,6 +256,8 @@ export class Table implements OnInit, AfterContentInit, BlockableUI {

_value: any[] = [];

_columns: any[];

_totalRecords: number = 0;

filteredValue: any[];
Expand Down Expand Up @@ -429,6 +435,14 @@ export class Table implements OnInit, AfterContentInit, BlockableUI {
this.tableService.onValueChange(val);
}

@Input() get columns(): any[] {
return this._columns;
}
set columns(cols: any[]) {
this._columns = cols;
this.tableService.onColumnsChange(cols);
}

@Input() get totalRecords(): number {
return this._totalRecords;
}
Expand Down Expand Up @@ -1823,6 +1837,8 @@ export class ScrollableView implements AfterViewInit,OnDestroy,AfterViewChecked
subscription: Subscription;

totalRecordsSubscription: Subscription;

columnsSubscription: Subscription;

initialized: boolean;

Expand All @@ -1831,7 +1847,6 @@ export class ScrollableView implements AfterViewInit,OnDestroy,AfterViewChecked
this.zone.runOutsideAngular(() => {
setTimeout(() => {
this.alignScrollBar();
this.setScrollHeight();
}, 50);
});
});
Expand All @@ -1845,6 +1860,16 @@ export class ScrollableView implements AfterViewInit,OnDestroy,AfterViewChecked
});
});
}

if (this.frozen) {
this.columnsSubscription = this.dt.tableService.columnsSource$.subscribe(() => {
this.zone.runOutsideAngular(() => {
setTimeout(() => {
this.setScrollHeight();
}, 50);
});
});
}

this.initialized = false;
}
Expand Down Expand Up @@ -2037,6 +2062,11 @@ export class ScrollableView implements AfterViewInit,OnDestroy,AfterViewChecked
if(this.totalRecordsSubscription) {
this.totalRecordsSubscription.unsubscribe();
}

if(this.columnsSubscription) {
this.columnsSubscription.unsubscribe();
}

this.initialized = false;
}
}
Expand Down

0 comments on commit f29be5a

Please sign in to comment.