From c8ee889272dfc424dce831dee90be0a1d0223178 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 5 Apr 2017 14:19:37 -0400 Subject: [PATCH] Watch for changes in table data in corTable control Prevents stale data from appearing in the table --- .../js/directives/ui/cor-table/cor-table.component.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/static/js/directives/ui/cor-table/cor-table.component.ts b/static/js/directives/ui/cor-table/cor-table.component.ts index feb681fb4..cc0e23c38 100644 --- a/static/js/directives/ui/cor-table/cor-table.component.ts +++ b/static/js/directives/ui/cor-table/cor-table.component.ts @@ -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) {