问题描述
我正在使用材料分页器来分页一些自定义卡片.我做了一个选择器来过滤数据.当我更改选择器值时,我想触发分页器转到第一页事件.因为例如,当我查看第 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 文件上触发转到第一页事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!