简体   繁体   English

如何持久化 Angular mat-paginator 数据?

[英]How to persist Angular mat-paginator data?

Our project have over ten tables with different types of data.我们的项目有十多个不同类型的数据表。 For each table we already use mat-paginator to pagination goals.对于每个表格,我们已经使用mat-paginator来分页目标。 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 .我在官方Angular Material 网站上找不到有关mat-paginator持久性功能的任何信息。

Could someone point me out how is it better to implement such functionality in Angular?有人可以指出在 Angular 中实现这样的功能有什么更好的方法吗?

If you take a look at the API tab of the mat paginator documentation you can see it accepts pageIndex and pageSize as inputs.如果您查看mat paginator 文档的 API 选项卡,您会发现它接受pageIndexpageSize作为输入。

I would go ahead and use this part of the mat-paginator API to set the page size and page index to my liking.我会提前 go 并使用垫子分页器 API 的这一部分来设置我喜欢的页面大小和页面索引。 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.然后,我会提前 go 并将我的分页器的 state 保存在localStoragesessionStorage中(取决于持久性需要),然后读取我在页面加载时需要的值并设置分页器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM