Home > Software design >  How to persist Angular mat-paginator data?
How to persist Angular mat-paginator data?

Time:07-25

Our project have over ten tables with different types of data. For each table we already use mat-paginator to pagination goals. Now I want to add persistence so next time user open one of tables he/she could view data sorted in the same way as he/she has sorted it the previous time.

I could not find any information about persistence feature for mat-paginator on official Angular Material site.

Could someone point me out how is it better to implement such functionality in Angular?

CodePudding user response:

If you take a look at the API tab of the mat paginator documentation you can see it accepts pageIndex and pageSize as inputs.

I would go ahead and use this part of the mat-paginator API to set the page size and page index to my liking. I would then go ahead and save the state of my paginators in localStorage or sessionStorage (depending on the persistence needs), then read the values I need on page load and set up the paginators.

  • Related