Pathik Vejani
Pathik Vejani

Reputation: 4491

refresh angular material data table dataSource when button clicked

I want to refresh data-table when click on one button. There are 3 buttons.

Example: stackblitz (not redirecting to customer page)

I am not getting why it's not updating the list in data-table. Data table is generic. So need to pass only data source.

Upvotes: 0

Views: 2672

Answers (1)

yurzui
yurzui

Reputation: 214017

If you expect that your custom data-table wrapper should respond to input changes then you need to handle this behavior either in ngOnChanges or using setters:

ngOnChanges(changes: SimpleChanges) {
  if (changes['tableData']) {
    this.dataSource = new MatTableDataSource(this.tableData);
    this.displayedColumns = this.columnHeader.map(c => c.columnDef);
  }
}

Forked Stackblitz

Upvotes: 1

Related Questions