I have a grid that contains heavy data to be loaded and so the loading time became not manageable. The solution I found was do a sequential number of http requests, each one retrieving batches of 100 rows, till fulfill all data on the grid. I know how to implement 2 sequential http requests using concatMap and it works perfectly but I would like to have a while loop that would validate each response and if the current number of rows < total number of rows then subscribe a new Http request. It's strange I don't find any solution for this, maybe I'm thinking wrong from the very beginning this solution :D
Any help would be very welcome! Thanks in advance!
Forwarding code used for execute 2 http requests using concatMap:
private LoadGridStringResourcesInProject(projectId: number) {
let allData: StringResource[] = [];
const batchSize = 100;
this.stringResourcesService.getStringResourcesInProject(projectId, 0, batchSize)
.pipe(
concatMap(firstData => {
const stringResourcesInProject = firstData as StringResource[];
// Loads first 100 rows on the Grid
this.gridApi.updateRowData({ add: stringResourcesInProject });
this.agGridService.refreshSizeColumns(this.agGrid);
// Fetch data returned by partial Http requests
allData = stringResourcesInProject;
if (allData && allData.length == batchSize) {
// Do new Http request to fetch the remaining data
return this.stringResourcesService
.getStringResourcesInProject(projectId, batchSize, 0);
}
return [];
})
).subscribe(data => {
const stringResourcesInProject = data as StringResource[];
// Loads the remaining rows in the Grid
this.gridApi.updateRowData({ add: stringResourcesInProject });
// Fetch data returned by partial Http requests
allData = allData.concat(stringResourcesInProject);
},
error => of(null),
() => {
this.agGridService.refreshSizeColumns(this.agGrid);
});
}