问题描述
我正在使用物料分页器对某些自定义卡片进行分页.我做了一个选择器来过滤数据.当我更改选择器值时,我想触发分页器转到首页事件.因为例如当我查看第10页并更改了过滤器的值时,如果我没有足够的数据显示在10.page上,则显示空白页.
Im using material paginator for paging some custom cards. And i made a selector for filter the data. I want to trigger paginator go to first page event when i changed the selector value. Because for example while im looking at page 10 and changed filter value paginator show me the empty page if i dont have enough data to show at 10.page.
推荐答案
我解决了我的问题.解决方案;导入
I solved my problem. Solution;import
import { MatPaginator } from '@angular/material';
这在您的.ts文件中.(不是app.module.ts)
this at your .ts file. (not app.module.ts)
将此添加到同一文件
@ViewChild(MatPaginator) paginator: MatPaginator;
在选择器数据更改事件上调用此功能
call this funtion at your selector data change event
this.paginator.firstPage();
最后,您应该更改分页器的长度,我就是这样;
lastly you should change your paginator length, i made this like that;
this.paginator.length=mock.length;
这篇关于Angular Material Paginator:如何在ts文件上触发转到首页事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!