1

hi I want to update the datatable without reload the page

 dataSource = new UserDataSource(this.userService);
  displayedColumns = ['insertId', 'name', 'email', 'mobile', 'actions'];

this is how i am able to display the data

and i am addding the new data using this api with dialog box

 dialogRef.afterClosed().subscribe(data => {
      console.log(data);
      this.userService.makeRegister(token, data)
        .subscribe(res => { console.log(res); });
    });

now i want to show this new data inside data table without reloading

1 Answer 1

2

It's very simple actually :

private updateTableData(data: any[]) {
  this.dataSource = data && data.length ? new MatTableDataSource(data) : new MatTableDataSource([]);
}

Either you create an empty source, or a source with no lines, up to you !

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

2 Comments

instead of empty array i called new MatTableDataSource(this.userService); thanks a ton
No problem, remember to mark your issue as resolved !

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.