0

I am Using Angular Mat Table to populate the data from database everything is working fine but the only issue is if some record in my database is updated,mat table does not update the view,i have to refresh the page in order to view the changes in the record.I want A real time update using mat table is it possible?

Below Given is my code

dataSource: macDataSource;
this.dataSource = new macDataSource(this.MacService);
this.dataSource.loadMacs('', 'asc', 0, 10);
loadMacPage()
{
 this.dataSource.loadMacs(this.search_sims.nativeElement.value, this.sort.direction, this.paginator.pageIndex, this.paginator.pageSize);
}
ngAfterViewInit()
{
 fromEvent(this.search_sims.nativeElement, 'keyup').pipe(tap(async () => {
 this.paginator.pageIndex = 0;
 this.loadMacPage();
 })).subscribe();
 this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);
 merge(this.sort.sortChange, this.paginator.page).pipe(tap(() => this.loadMacPage())).subscribe();
 this.ngx.stop();
}
export class macDataSource extends DataSource<MacModel[]>
{
 private macSubject = new BehaviorSubject<MacModel[]>([]);
 private loadingSubject = new BehaviorSubject<boolean>(false);
 public loading$ = this.loadingSubject.asObservable();
 public macLength: any;
 public macData: any;
 constructor(private macService: MacService) {
 super();
 }
 connect(collectionViewer: CollectionViewer): Observable<any> {
 return this.macSubject.asObservable();
 }
 disconnect(collectionViewer: CollectionViewer): void {
 this.macSubject.complete();
 this.loadingSubject.complete();
 }
 loadMacs(filter = '', sortDirection = 'asc', pageIndex = 0, pageSize = 10) {
 this.loadingSubject.next(true);
 this.macService.getAllmacs(filter, sortDirection, pageIndex, pageSize).pipe(catchError(() => of([])), finalize(() => this.loadingSubject.next(false)))
 .subscribe(macs => { this.macSubject.next(macs); this.macLength = macs.length; this.macData = macs; this.loadingSubject.next(macs) });
 }
 getLength(): String {
 return this.macLength;
 }
}
asked Aug 2, 2019 at 12:16
10
  • yes, it's possible ;) Commented Aug 2, 2019 at 12:19
  • how should i achieve that without using mongo streams Commented Aug 2, 2019 at 12:20
  • You need to show us your code and where you are facing an issue. No one can help otherwise. Commented Aug 2, 2019 at 12:20
  • How does your table get the data from the database? Commented Aug 2, 2019 at 12:21
  • @AJT_82 i have my code in the question Commented Aug 2, 2019 at 12:30

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.