Having difficulty populating the MatTableDataSource when the application starts up. Upon startup, the table is empty with a *matNoDataRow message displayed. However, once I click on any column to sort or input anything in the filter, the data immediately appears.
I attempted using hardcoded values for table rows and it worked fine - everything loaded upon startup. I have a functional StackBlitz example where I replicated everything except for the subscription because it retrieves values from my database: StackBlitzExampleOfHardcodedArray
I also tried populating an array in the service and calling it in the component after it's done loading but unfortunately, the rows still did not show.
This is my original method:
parseUserData: any;
returnValue: any = [];
getAllBooksFromDatabase(): BooksData[] { //all books from Bookshelf
this.returnValue.splice(0, this.returnValue.length);
this.data.getBooks().subscribe((data: any) => {
this.parseUserData = JSON.parse(JSON.stringify(data));
this.parseUserData.map((item: any) => {
if (item.fine != 0) {
this.returnValue.push({
uid: item.uid,
bid: item.bid,
bookTitle: item.bookTitle,
authorLastName: item.authorLastName,
authorFirstName: item.authorFirstName,
issuedDate: item.issuedDate,
period: item.period,
fine: item.fine,
warning: item.warning
});
}
})
return this.returnValue;
}
}
EDIT: This is my service method for fetching data:
public getBooks(): Observable<any> {
return this.http.get('http://localhost:8080/books')
.pipe(map((books: any) => books));
}
EDIT: Here is part of the result - books:
[
{
"warning": "",
"issuedDate": "in library",
"period": "0",
"bookTitle": "Balade Petrice Kerempuha",
"bid": "158744286",
"fine": "0",
"authorLastName": "Krleža",
"authorFirstName": "Miroslav",
"bookGenre": "poetry",
"uid": ""
},
...
]
How can I display all table rows upon startup?
Your advice is greatly appreciated. Thank you!