简体   繁体   English

Aurelia.js框架aurelia表分页显示项目数量

[英]Aurelia.js Framework aurelia-table pagination showing amount of items

I am using : https://tochoromero.github.io/aurelia-table/ 我正在使用: https : //tochoromero.github.io/aurelia-table/

I have just a small issue and I would like ask your help. 我只有一个小问题,我想请您帮忙。

<table class="table table-striped" aurelia-table="data.bind: 
    filters.bind: filters;
    current-page.bind: currentPage; 
    page-size.bind: pageSize; 
    total-items.bind: totalItems;">
</table>

<label>${currentPage} - ${pageSize} of  ${totalItems}</label>

I have 5 pages and 52 items I would show like: 1 - 10 of 52 items,11 -20 of 52 items, 21 - 30 of 52 items. 我有5页,要显示52个项目:52个项目中的1-10个,52个项目中的11-20个,52个项目中的21-30个。

not sure if aurelia table hs this, so I tried do this using just JS, but not sure if this is right: 不知道aurelia表是否具有此功能,因此我尝试仅使用JS进行此操作,但不确定是否正确:

 getPageStart(pageSize, pageNr) {
   return pageSize * pageNr;
 }

 getPageLabel(total, pageSize, pageNr) {
   const start = Math.max(
     this.getPageStart(pageSize, pageNr),
     0
   );
   const end = Math.min(
     this.getPageStart(pageSize, pageNr + 1),
     total
   );

   return `${start + 1} - ${end}`;
 }
 attached() {
   this.itemsToShow = Array.from({ length: 22 }, (_, i) => `Item ${i + 1}`);
   this.size = 10;
   this.pages = Array.from( {
     length: Math.ceil(this.itemsToShow.length / this.size) },
     (_, i) => this.getPageLabel(this.itemsToShow.length, this.size, i));
      logger.info('here is what I want to see');
      console.log(this.pages+'pages');
      logger.info('pages'+ this.pages);
 }

I am getting the results: "1 - 10", "11 - 20", "21 - 22" 我得到的结果是:“ 1-10”,“ 11-20”,“ 21-22”

but will be possible to get this just with aurelia table? 但是有可能只用aurelia表就能做到这一点? I set 22 for the items this can be automatic calculating the real ammount of rows of my table? 我将项目设置为22,这可以自动计算表格中的实际行数吗? right now as well am getting all the same time: "1 - 10", "11 - 20", "21 - 22", how can I do this to appear for each page? 现在也都在同一时间获取:“ 1-10”,“ 11-20”,“ 21-22”,我该如何在每个页面上显示呢? eg.: 1- 10 if I am in page one after I click to go to the page 2 show 11 -20, right now I amgetting all at the same time. 例如:1- 10如果我单击进入第2页显示11 -20后进入第一页,那么现在我同时获取所有内容。

On the page you linked there is also mentioned a pagination component. 在您链接的页面上,还提到了分页组件。 Which requires also a currentPage, pageSize and totalItems. 这还需要currentPage,pageSize和totalItems。

These three are all you need to show your label as you want. 这三个都是您想要显示标签所需要的。

${((currentPage-1)*pageSize+1)} - ${currentPage*pageSize} of ${totalItems}

That'll not give you the correct upper value for last page. 这不会给您最后一页的正确上限值。

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

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