简体   繁体   English

Aurelia.js 框架 aurelia-table 分页

[英]Aurelia.js Framework aurelia-table pagination

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 I would show like: 1 of 5 pages os 33 items, I tried use: pagination-size: but did not work for me, can someone help me with this?我有 5 页,我想显示如下:5 页中的 1 页 os 33 个项目,我尝试使用: pagination-size:但对我不起作用,有人可以帮助我吗? thank you.谢谢。

If you have your total amount of items, and you know how many are gonna be on each page, it's a matter of simple math.如果你有你的物品总数,并且你知道每页上会有多少,这是一个简单的数学问题。

// Compute the amount of pages.
var amountOfPages = Math.ceil(totalItems / pageSize);

HTML: HTML:

<!-- two-way binding as suggested in the comments to update the variables in the viewmodel -->
<table class="table table-striped" aurelia-table="data.bind: data;
  filters.bind: filters;
  current-page.two-way: currentPage; 
  page-size.bind: pageSize; 
  total-items.two-way: totalItems;">
</table>
<label>Page: ${currentPage} of ${amountOfPages} (${totalItems} items)</label>

If you data is dynamic and can update, you can turn the variable into a get -function:如果数据是动态的并且可以更新,则可以将变量转换为get函数:

@computedFrom('totalItems', 'pageSize')
public get amountOfPages() {
  return Math.ceil(totalItems / pageSize);
}

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

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