MatPaginator无法正常工作从MatTableDataSource删除行 [英] MatPaginator not working properly on deleting rows from MatTableDataSource

查看:80
本文介绍了MatPaginator无法正常工作从MatTableDataSource删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个表格,其中使用角度材质在角度2中进行选择和分页.

I have created a table with selection and pagination in angular 2 using angular material.

我已使用名称为 Remove Selected Rows 的按钮删除了表中的选定行.

I have taken a button with the name Remove Selected Rows to delete the selected rows from the table.

但是作为删除所选行的方法,所有表数据都将被加载,该数据与为分页指定的值不匹配.

But as a delete the selected rows , all the table data is being loaded which doesn't match with value specified for the pagination.

https://stackblitz.com/edit/delete-rows-mat-table-vj4hbg?file=app%2Ftable-selection-example.html

最初,表格仅显示为分页值指定的行.

Initially the table displays only the rows as specified for the pagination value.

但是当我删除第3行时,即使分页值仅为3,所有行也都将被加载.

But as I deleted the row 3 , all rows are being loaded even if the pagination value is only 3..

有人可以告诉我删除行后如何用指定的分页值限制我的表行.

can anybody tell me how can I limit my table rows with the pagination value specified after deleting the rows.

推荐答案

Here you go buddy.

删除后,您忘记将分页器重新分配给数据源. Angular可以做一些魔术,但有时需要一点帮助.

You forgot to reassign the paginator to the datasource after deletion. Angular may do some magic, but sometimes it needs a little bit of help.

我使用超时是因为我总是遇到问题,请随时尝试.

I use a timeout because I always face an issue, feel free to try without it.

setTimeout(() => {
  this.dataSource.paginator = this.paginator;
});

这篇关于MatPaginator无法正常工作从MatTableDataSource删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆