0

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.

6
  • alternatively, you can assign new data to this.tableData so MatDataSource automatically refreshed Commented Nov 22, 2019 at 12:07
  • @GaurangDhorda how to assign? Commented Nov 22, 2019 at 13:43
  • 2
    Share stackblitz of your code if possible Commented Nov 22, 2019 at 14:58
  • @GaurangDhorda Ok. I'll try to do that. Commented Nov 25, 2019 at 3:38
  • @GaurangDhorda I have created stackblitz.com/edit/angular-jxh2rd but it's not redirecting. Commented Nov 25, 2019 at 4:43

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

9 Comments

You should also reassign those properties related to pagination
I updated stackblitz stackblitz.com/edit/…
Please note I used { static: true } for ViewChild
what happens with { static: true } ?
With static true those properties(this.sort, this.paginator) will be available in NgOnChanges otherwise they will be undefined
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.