After importing a big database with more than 13.000 documents, I'm experiencing a big delay when displaying the data in my angular material table. I already tried to load the data asynchronously to the table, but was unable to do it. Can someone guide me?
This is how I'm retrieving the data in my component.
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
loadDocuments() {
this._documentService.getDocuments().subscribe((data: Document[]) => {
this.documents = data
this.dataSource = new MatTableDataSource<Document>(this.documents );
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort
this.sort.sort(<MatSortable>{
id: 'name',
start: 'asc'
});
})
}
// searching function
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
I've been checking some examples and what they do is declaring as observable datasource... but i could not adapt it.
//EDITED
In my nodejs i have this code
documentsCtrl.getDocuments = (req, res) => {
documentsModel.find().then((documents) => {
res.json(documents)
}).catch(err => {
res.json(err)
})
}
This function just find all documents that i want retrieve in my component.
This request takes like 4000ms more or less to be displayed in my client
So til this request is completed... i have other function that show a loading spin in my table... but it takes like 4 or 5 seconds to show the data ( the time that the request needs to be completed ) how can i improve this performance?