Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pavankjadda/161fca7fe179b1c0369bcb98357edf76 to your computer and use it in GitHub Desktop.
Save pavankjadda/161fca7fe179b1c0369bcb98357edf76 to your computer and use it in GitHub Desktop.
/**
* Maps Employees to mat-table data format
*
* @author Pavan Kumar Jadda
* @since 1.0.0
*/
private mapTableData(data: UserData[]) {
this.dataSource = new MatTableDataSource<UserData>(data);
if (this.optionalParamsPresent()) {
this.sort.active =
this.route.snapshot.queryParamMap.get('sortBy') ?? 'id';
//@ts-ignore
this.sort.direction =
this.route.snapshot.queryParamMap.get('sortDirection') ?? 'desc';
this.paginator.pageIndex =
Number.parseInt(
this.route.snapshot.queryParamMap.get('pageIndex') as string,
10
) ?? 0;
this.paginator.pageSize =
Number.parseInt(
this.route.snapshot.queryParamMap.get('pageSize') as string,
10
) ?? 10;
this.searchTextControl.patchValue(
this.route.snapshot.queryParamMap.get('searchText') ?? ''
);
this.dataSource.filter =
this.route.snapshot.queryParamMap.get('searchText') ?? '';
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
this.cdr.detectChanges();
} else {
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment