I am using Angular Material datatable with Http request to get data.
However, it is not sorting data in Data table.
export class ContactComponent implements OnInit, AfterViewInit {
displayedColumns: string[] = [
"firstname",
"middlename",
"lastname",
"status",
"dateofbirth"
];
selected;
dataSource = new MatTableDataSource<Yuvak>();
constructor(
private router: Router,
private dialogService: NbDialogService,
private contactService: ContactService
) { }
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
ngOnInit() {
this.contactService.getAllUser().subscribe(
data => {
this.dataSource.data = data.data.user;
},
error => {
console.log("There was an error while retrieving Users !!!" + error);
}
)
}
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
}
above is my ts file. Previously when i was loading data from local json file it was working fine inside constructor. However, now i am getting data from GET request.