Watch for changes in table data in corTable control

Prevents stale data from appearing in the table
This commit is contained in:
Joseph Schorr 2017-04-05 14:19:37 -04:00
parent 288ef0f5b5
commit c8ee889272

View file

@ -10,7 +10,7 @@ import { CorTableColumn } from './cor-table-col.component';
transclude: true,
})
export class CorTableComponent implements ng.IComponentController {
@Input('=') public tableData: any[];
@Input('<') public tableData: any[];
@Input('@') public tableItemTitle: string;
@Input('<') public filterFields: string[];
@Input('@') public compact: string;
@ -30,6 +30,12 @@ export class CorTableComponent implements ng.IComponentController {
};
}
public $onChanges(changes: ng.IOnChangesObject): void {
if (changes['tableData'] !== undefined) {
this.refreshOrder();
}
}
public addColumn(col: CorTableColumn): void {
this.columns.push(col);
@ -64,7 +70,8 @@ export class CorTableComponent implements ng.IComponentController {
return col.isNumeric();
}).map((col) => (col.datafield));
var processed = this.tableData.map((item) => {
var tableData = this.tableData || [];
var processed = tableData.map((item) => {
var keys = Object.keys(item);
var newObj = {};
for (var i = 0; i < keys.length; ++i) {