angular js中的分页 [英] Pagination in angular js

查看:23
本文介绍了angular js中的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过http post调用从数据库中获取数据并渲染表.好的实现代码看起来不错,但是,分页似乎不起作用.

I am getting the data from database via http post call and rendering the table. Well the implementation code looks fine however, the pagination doesn't seem to work.

我根据自己的要求实施了该程序,并得到了我在chrome控制台中看到的响应.分页可能出了什么问题,因为我看不到任何分页按钮.

I implemented it according to my requirement and I get the response which I can see in chrome console. What could be wrong with the pagination as I am not able to see any pagination buttons.

这是代码:

 <!doctype html>
    <html lang="en" ng-app="myApp">
        <head>
            <meta charset="utf-8">
            <base href="/">
            <title>The Single Page Blogger</title>
            <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.min.js"></script>
            <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
            <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
            <script data-require="ui-bootstrap@*" data-semver="0.12.1" src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.min.js"></script>
            <script src="<%=request.getContextPath()%>/js/module.js"></script>
            <link rel="stylesheet" href="<%=request.getContextPath()%>/style2.css" />
            <script>

                //Get table from Server and do pagination
                app.controller("tableController", function ($scope, $http) {
                    $scope.filteredTodos = []
                            , $scope.currentPage = 1
                            , $scope.numPerPage = 10
                            , $scope.maxSize = 5;

                    $scope.getTable = function () {
                        $scope.customerTable = [];

                        $http.get('<%=request.getContextPath()%>/GetTable.do').success(function (data)
                        {
                            $scope.customerTable = data;
                        });
                    };
                    $scope.getTable();

                    $scope.$watch("currentPage + numPerPage", function () {
                        var begin = (($scope.currentPage - 1) * $scope.numPerPage)
                                , end = begin + $scope.numPerPage;

                        $scope.filteredTodos = $scope.customerTable.slice(begin, end);
                    });
                });

            </script>
        </head>
        <body>
            <div class="container" id="main"><br/><br/>
                Search: <input type="text" ng-model="search" placeholder="Search">
                <div ng-controller="tableController">
                    <table class="table table-striped table-hover table-bordered">
                        <tr>
                            <th style="font-size: 13.3px">Card number</th>
                            <th style="font-size: 13.3px">First name</th>
                            <th style="font-size: 13.3px">Opening balance</th>
                            <th style="font-size: 13.3px">Withdrawal</th>
                            <th style="font-size: 13.3px">Deposit</th>
                            <th style="font-size: 13.3px">Closing balance</th>
                            <th style="font-size: 13.3px">Tx date</th>
                            <th style="font-size: 13.3px">Usage type</th>
                        </tr>
                        <tr ng-repeat="data in customerTable| filter: search">
                            <td>{{data.CARD_NUMBER}}</td>
                            <td>{{data.FIRST_NAME}}</td>
                            <td>{{data.OPENING_BALANCE}}</td>
                            <td>{{data.WITHDRAWAL}}</td>
                            <td>{{data.DEPOSIT}}</td>
                            <td>{{data.CLOSING_BAL}}</td>
                            <td>{{data.TXDATE}}</td>
                            <td>{{data.USAGE_TYPE}}</td>
                        </tr>
                    </table>
                    <pagination 
                        ng-model="currentPage"
                        total-items="customerTable.length"
                        max-size="maxSize"  
                        boundary-links="true">
                    </pagination>
                    <br/><br/><br>
                    </form>
                </div>
            </div>
        </body>
    </html>

这是pl人: http://plnkr.co/edit/eNgT4bVroGIla4EOdkNZ?p=preview

模块:

var app = angular.module('myApp', ['ui.bootstrap']);

推荐答案

尝试一下,

                <tr ng-repeat="data in filteredTodos| filter: search">
                            <td>{{data.CARD_NUMBER}}</td>
                            <td>{{data.FIRST_NAME}}</td>
                            <td>{{data.OPENING_BALANCE}}</td>
                            <td>{{data.WITHDRAWAL}}</td>
                            <td>{{data.DEPOSIT}}</td>
                            <td>{{data.CLOSING_BAL}}</td>
                            <td>{{data.TXDATE}}</td>
                            <td>{{data.USAGE_TYPE}}</td>
                        </tr>

您应该迭代 filteredTodos 而不是 customerTable

这篇关于angular js中的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆