• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
飞呀肥呀肥
博客园    首页    新随笔    联系   管理    订阅  订阅
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>
posted on 2014-03-01 03:35  ruijiang21  阅读(1644)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3