Let me preface this question by stating that I am fairly new to Angular and this is my first experience with material table. I have a material table that resides in one component. I have a data fetching routine that resides in another component. Based on some selection made in this second component I need to update the data in the material table. I am not sure how I can go about doing this, and all my experimenting has failed. I have tried looking for questions on this forum that address a similar scenario and have not been successful so far.
I have tried to bind the material table's typescript file variable directly and via an emitter but the only time I see data is on ngInit of the second form (the one that computes the data). Thereafter, when the data is updated (see performButtonClickAction() below) I see that the data is correctly populated in the emitter but does not show up in the table. I guess that I need to know how to trigger an update / refresh event in the material table component.
Component that fetches data:
<div>
<div >
<div >
<div >
<button (click)="performButtonClickAction('ManualReview')"> </button>
</div>
<div >
<button (click)="performButtonClickAction('PendingCustomer')"></button>
</div>
<div >
<button (click)="performButtonClickAction('DecisionRendered')"></button>
</div>
<div >
<button (click)="performButtonClickAction('RefreshComplete')"></button>
</div>
<div >
<button (click)="performButtonClickAction('AllMyDeals')"> </button>
</div>
</div>
<div >
<op-credit-view-body-table [data]="refreshDetails" ></op-credit-view-body-table>
</div>
</div>
</div>
In the html above op-credit-view-body-table [data]="refreshDetails" is a reference to the material table component.
Typescript file methods that fetches data when some selection is made:
@Output() updatedRecords = new EventEmitter<RefreshDetailRecords[]>();
performButtonClickAction(value: string) {
this.currentRefreshSelected = RefreshType[value];
if (this.currentRefreshSelected == 4)
this.refreshDetails = this.fundationService.getRefreshedRecords();
else
this.refreshDetails = this.refreshDetails.filter(x => x.currentStatusId == this.currentRefreshSelected);
this.updatedRecords.emit(this.refreshDetails);
}
Material table typescript file:
@Input() data: RefreshDetailRecords[]; <-- This is set in the html snippet shown above
ngOnInit() {
this.dataSource = new CreditViewBodyTableDataSource();
this.dataSource.data = this.data;
}
The result that I am looking for is as that when the second form executes the performButtonClickAction() action, and the refreshDetailRecords[] object is updated, I need to somehow pass that message back to the material table component and have it update the table.
The current route is as follows:
The data fetching component's ts file initializes the data object refreshDetailRecords[] in the ngInit() method.
The data fetching form initialize the material tables "data" object in its own html as follows:
Material Datasource data resides in material component's ts file