简体   繁体   English

限制angular4中的分页

[英]limit pagination in angular4

I try apply pagination in angular4 but I don't khnow how to apply limit in pagination .. limit : for example I have 1000 pagination how to display in the first 5 pagination then ... then last page : 1 2 3 4 5 .... 1000. in my code I display all pagination 1000 pagination but isn't not good design for client: 我尝试在angular4中应用分页,但是我不知道如何在分页中应用限制。限制:例如,我有1000个分页,在前5个分页中如何显示,然后在最后一页中显示:1 2 3 4 5。 ...1000。在我的代码中,我显示所有的分页1000的分页,但对客户而言并不是很好的设计:

code component: 代码部分:

addClass(x)
{
    $(".page-item").click(function () {
        $(this).addClass("current").siblings().removeClass('current');
    });
}

next()
{ 
    $('.current').next('.page-item').trigger('click'); 
}
previous()
{
     $('.current').prev('.page-item').trigger('click'); 
}

code html: 代码html:

<ul>
   <li class="previous" (click)="previous()">Previous</li>
   <li class="next" (click)="next()">Next</li>
</ul>
<ul class="pagination">
<li *ngFor="let x of pages" class='page-item' (click)='addClass(x)'>
    {{x}}
</li>

and this is screenshot of display in my page: 这是我页面中显示的屏幕截图:

在此处输入图片说明

Some hint: 一些提示:

  • You create a pages array containing 1,2,3,4,5... MAX before loading the html 创建一个包含1,2,3,4,5 ... MAX的页面数组,然后再加载html
  • When clicking next, previous or directly on a page, you recreate the array, if the new page is greater than current +/- 5 如果下一页,上一页或直接在页面上单击,则在新页面大于当前+/- 5的情况下,您将重新创建数组

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

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