AngularJS Boostrap Pagination Sample

首先,样式是这样的

image

首先,Service端是Webapi REST JSON格式

第二,我们建立一个Wrapper Class,这里你也可以定义一个Generic<T>,作为示例,我们这里直接使用List<Employee>

image

image

后端分页使用Entity Framework,这里呢,pageSize我们默认为5,

image

示例的JSON结果

image

然后我们要引用两个AngularJS,一个是AngularJS本身,一个是AngularJS Boostrap

PM> Install-Package angularjs

PM> Install-Package Angular.UI.Bootstrap

image

剩下的就是代码了

<h3>This is done by AngularJS</h3>
<ul>

    <script>
        angular.module('myApp', ['ui.bootstrap']);
       
        function pagerCtrl($scope, $http) {
            $scope.maxSize = 5;
            $scope.bigCurrentPage = 1;
            $scope.setPage = function (pageNo) {
                $scope.bigCurrentPage = pageNo;
            };
            $scope.$watch(
                "bigCurrentPage",
                function(newValue, oldvalue) {
                    doPaging(newValue);
                  
                }
            );
            $scope.init = function (pageIndex) {
                doPaging(pageIndex);
            };
            function doPaging(pageIndex) {
                var url = "/api/employee/page/" + pageIndex;
                $http.get(url).success(function (data) {
                    $scope.employeeList = data;
                    var number = new Number(data.TotalCount);
                    //alert(number);
                    $scope.bigTotalItems = number;
                });
            }
        }

    </script>

</ul>
<div class="container" ng-app="myApp" ng-controller="pagerCtrl">
    <table data-ng-init="init(1)">
        <tr>
            <td>First Name</td>
            <td>Last Name</td>
        </tr>
        <tr ng-repeat="item in employeeList.Employees">
            <td>{{item.FirstName}}</td>
            <td>{{item.LastName}}</td>
        </tr>
    </table>
    <pagination total-items="bigTotalItems" items-per-page="5" page="bigCurrentPage"  class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>
    <pre>Page: {{bigCurrentPage}} / {{numPages}}</pre>
</div>

转载于:https://www.cnblogs.com/ruijiang21/p/3574644.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值