我正在使用智能表来显示记录。使用自定义分页显示每页 20 条记录。
我想显示如下分页: 25 条记录中的 1-20 条 我怎样才能做到这一点?- 我尝试使用(页数 * 总页数),但这会对结果进行四舍五入。
我正在使用智能表来显示记录。使用自定义分页显示每页 20 条记录。
我想显示如下分页: 25 条记录中的 1-20 条 我怎样才能做到这一点?- 我尝试使用(页数 * 总页数),但这会对结果进行四舍五入。
您可以使用totalItemCount
which is present inside tableState.pagination
。从服务器获取数据并在分页模板中使用该值后,只需填充该值。
受 dhiraj tiwari 答案的启发,除非包含在函数调用中,否则手表将无法工作:
.directive('stPaginationSummary', function () {
return {
restrict: 'E',
require: '^stTable',
template: '<span>Showing <strong>{{from}}</strong>-<strong>{{to}}</strong> of <strong>{{total}}</strong> Record(s)</span>',
scope: {},
link: function (scope, element, attr, ctrl) {
var listener = function () {
var pagination = ctrl.tableState().pagination
scope.from = pagination.totalItemCount === 0 ? 0 : pagination.start + 1
scope.to = Math.min(pagination.start + pagination.number, pagination.totalItemCount)
scope.total = pagination.totalItemCount
}
scope.$watch(function () {
return ctrl.tableState()
}, listener, true)
}
}
})
首先你应该创建指令
ticketsApp.directive('stSummary', function () {
return {
restrict: 'E',
require: '^stTable',
template:'<span><b>[[pagination.start ]] of [[pagination.totalItemCount]] items</b></span>',
scope: {},
link: function (scope, element, attr, ctrl) {
var listener = function (val) {
scope.pagination = ctrl.tableState().pagination;
scope.to = Math.min(scope.pagination.start + scope.pagination.number, scope.total || 0);
};
scope.$watch(ctrl.tableState(), listener, true);
}
}
});`
之后,您应该在视图中使用“stSummary”标签。前任 :
<st-summary st-items-by-page="10"
class="pull-right"
class="pagination-info itemCountnumber">
</st-summary>`
我找到了解决我的问题的方法。我知道这是一个老问题,但为了使它对其他人更有帮助,我想展示如何使这个解决方案变得更好。
您给出的答案在第一页和后续页面上是正确的,但在最后一页上并不总是正确的。
你这样做:
<span class="pagination-info itemCount">
{{(currentPage-1)*stItemsByPage+1}}-
{{currentPage*stItemsByPage}}
of {{numPages*stItemsByPage}} Records
</span>
如果最后一页上的记录数少于 stItemsByPage,则永远不会正确。在这种情况下会更好:
<span class="pagination-info itemCount">
{{(currentPage-1)*stItemsByPage+1}}-
{{(currentPage*stItemsByPage) > totalItemCount?totalItemCount:(currentPage*stItemsByPage)}}
of {{numPages*stItemsByPage}} Records
</span>