HalitTalha / ng-material-extensions

Extended features for @angular/material components
Apache License 2.0
101 stars 52 forks source link

Server side pagination #84

Open diasandreotti opened 4 years ago

diasandreotti commented 4 years ago

I'm trying the same problem reported in #34. And I have the updated version of the angular

sbalmos commented 2 years ago

Likewise same issue here. The exporter does not seem to want to use a returned Promise, Observable, BehaviorSubject, anything that would have an async delay such as server-side delay. I have attached a minimal example here. The private getData() returning a Promise is meant to simulate the server-side paging with a 250ms response delay. The table display and paging display the 4 pages of 5 entries each fine. Exporting will only yield a CSV with the first page of 5 entries, however.

app.component.zip

ahmadabulaban commented 2 years ago

I'm facing same issue, i think the exporter doesn't wait for any delay caused by subscription of server side hits

sbalmos commented 2 years ago

I'm slowly peeling back the onion on this one. It's multi-faceted. At the root (so far), cdk-table-exporter attempts to collect all pages of a paged datasource before exporting by subscribing to the data source's page change Observable. In mat-table-exporter, this boils down to the MatPaginator's page event. But in the typical server-side paging scenario, this page event signals the start of a page change, not the completion of it. Almost all server-side paging tutorials show how to subscribe to this page event to catch a page change request and request the appropriate page from the backend. But, like I mentioned, this is the start of a page change.

I am currently investigating possibly replacing cdk-table-exporter's subscribing to the page change observable, and to have it subscribe to the underlying Data Source's connect() Subject. This Subject is what ultimately sends data to the Table to be rendered, and thus would be a better indicator of when the data is actually received from the backend. But MatTableDataSource has its own potential issues there related to how it tries to handle paging itself. It basically causes multiple "new data" events to be emitted. Too long to explain here, but it also explains why most server-side paging examples also require you to reset the MatPaginator's length, pageIndex, and pageSize properties again in a setTimeout() /after/ you have set the MatTableDataSource's data property. It's the MatTableDataSource trying to be smarter than you.

I'll let everyone know if I figure out anything useful.

rodriggit commented 2 years ago

I'm having this issue too. It would be nice to have a feature to export single page even when the paginator is present

yashagldit commented 1 year ago

@sbalmos Did you or anyone figure it out?

sbalmos commented 1 year ago

Not really. Some attempts sort of worked but ultimately still broke. I have since moved on to another position and no longer maintain the app where this functionality was relevant.