3

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.

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.

Here's the code:

 <!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> 

Here's the plunker: http://plnkr.co/edit/eNgT4bVroGIla4EOdkNZ?p=preview

Module:

var app = angular.module('myApp', ['ui.bootstrap']); 
9
  • I can see the pagination and everything seems to work fine Commented Jun 29, 2015 at 17:34
  • Yes its not working with my code. The plunker is just a demo Commented Jun 29, 2015 at 17:36
  • Do you have ['ui.bootstrap'] defined as a dependency injected? As in like, var app = angular.module('app', ['ui.bootstrap']); ?? Commented Jun 29, 2015 at 17:38
  • I can't see the ui-bootstrap-tpls-0.12.1.min.jsscript in your code, did you check you have everything like the plunker? Commented Jun 29, 2015 at 17:39
  • Yes just now I added it and tried but still didnt work Commented Jun 29, 2015 at 17:39

1 Answer 1

1

Try this,

 <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> 

You should be iterating filteredTodos instead of customerTable

Sign up to request clarification or add additional context in comments.

14 Comments

Unable to get response data on the view when I use filteredTodos
I can see the response in chrome console but using filteredTodos table is empty
Thats not the case always, yes it should but if you make it to be! For example, $http.get() sends an asynchronous call to the server, while the call is fetching data, the rest of the code would compile, hence sometimes you dont get the data ready in hand as the page loads. This is one amongst the various reasons why people use promises, $q s etc.
In your case you have a lot of dynamic compilation to be made, it's not only AngularJS part that is getting compiled but also, the CSS and js that you have imported on top seem to take some time as the path provided is getting compiled with respect to the Context using <%=request.getContextPath()%> I would suggest you to load these using relative paths.
@kittu found something for you :) stackoverflow.com/questions/20369377/…
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.