简体   繁体   English

如何在 angular 的 ng2-smart-table 中添加自定义分页?

[英]How to add customized pagination in ng2-smart-table in angular?

How do you handle pagination in ng2-smart-table in angular 7?您如何处理 angular 7 中的 ng2-smart-table 中的分页? I have a too many records and it would take too much time to load all of them.我有太多记录,加载所有记录需要太多时间。 How do i set the table to request 10 records at a time?如何将表格设置为一次请求 10 条记录? For example: when the table loads for the first time is requests the 10 first records.例如:第一次加载表时请求前10条记录。 When I press one of the pagination buttons, it requests the "n'th" records?当我按下其中一个分页按钮时,它会请求“第 n 个”记录? I've read the previous articles but I'm still unclear on how to handle this issue.我已经阅读了以前的文章,但我仍然不清楚如何处理这个问题。

Hoping that the request is being passed to server to fetch the data.希望将请求传递给服务器以获取数据。 If so add two parameters page index(refers to the page number) and page size(refers to number of rows per page) while handling with enitity framework or sql we can use skip and take logic to handle the pagination.如果是这样,在使用实体框架或 sql 处理时添加两个参数页面索引(指页码)和页面大小(指每页的行数),我们可以使用跳过并采取逻辑来处理分页。 ex: if my request has page_index=1 and page_size=20 then i need to return 1st 20 recs so the code will be basequery.skip(page_size*(page_index-1)).take(page_size);例如:如果我的请求有 page_index=1 和 page_size=20 那么我需要返回 1st 20 recs 所以代码将是 basequery.skip(page_size*(page_index-1)).take(page_size); like wise if the page_index=2 then it will skip 1st 20 and then take the next 20 recs.同样,如果 page_index=2 则它将跳过第 1 个 20,然后进行接下来的 20 个记录。

To handle in UI we can either add the pagersettings object of ng2-smart-table refer the doc https://akveo.github.io/ng2-smart-table/#/documentation or if we need a customise pagination we can use source.setPaging() method and it takes 3 parameters pagenumber,per page count of rows and a boolean to reload the table or not To handle in UI we can either add the pagersettings object of ng2-smart-table refer the doc https://akveo.github.io/ng2-smart-table/#/documentation or if we need a customise pagination we can use source .setPaging() 方法,它需要 3 个参数 pagenumber,每页行数和一个 boolean 来重新加载表

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

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