获取当前页面并移至NgPrime数据表中的特定页面 [英] Get current page and move to specific page in NgPrime datatable

查看:73
本文介绍了获取当前页面并移至NgPrime数据表中的特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用primefaces-primeNg中的数据表.我可以获取当前所在的页面,并以编程方式将数据表设置为特定页面吗?

I am using datatable from primefaces - primeNg. Can I get the current page I am in and set the datatable to particular page programatically?

我看到数据表在其中使用了分页组件,但是如何使用@ViewChild访问它呢? 任何帮助将不胜感激.

I saw that datatable uses pagination component within, but how to access it using @ViewChild? Any help will be appreciated.

推荐答案

<p-dataTable #dt [value]="items" [rows]="10" [paginator]="true" [(first)]="first"  (onPage)="paginate($event)">

解决方法-以编程方式将数据表设置为特定页面.

Work Around - To set the datatable to particular page programatically.

@ViewChild('dt') dataTable: DataTable;

setCurrentPage(n: number) {
    let paging = {
    first: ((n - 1) * this.dataTable.rows),
    rows: this.dataTable.rows
};
this.dataTable.paginate(paging);
}
// this.setCurrentpage(pageNumber) will set table to given page number

要获取您当前所在的页面,请使用像这样的(onPage)事件

To get the current page you are at, use (onPage) event like this

paginate(event) {
//event.first: Index of first record being displayed 
//event.rows: Number of rows to display in new page 
//event.page: Index of the new page 
//event.pageCount: Total number of pages 
let pageIndex = event.first/event.rows + 1 // Index of the new page if event.page not defined.
}

对于以下设置页码的方式似乎出现了缺陷.您可能需要使用变通方法,直到缺陷消除为止. 根据priming文档 要将数据表以编程方式设置到特定页面,请设置"first"为您要查看的行号. 例如

There seems to be a defect raised for below way of setting page number, so you may need to use work around until defect is closed. As per primeng documentation To set the datatable to particular page programatically please set 'first' with the row number you want to see. for example

this.first = 10 //will show second page, OR
this.first=20  //will show third page.

这篇关于获取当前页面并移至NgPrime数据表中的特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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