{"id":551,"date":"2014-10-10T23:42:12","date_gmt":"2014-10-10T23:42:12","guid":{"rendered":"http:\/\/www.honobono-life.info\/wpeng\/?p=551"},"modified":"2017-10-08T08:04:40","modified_gmt":"2017-10-08T08:04:40","slug":"angularjs-server-side-grid-paging","status":"publish","type":"post","link":"http:\/\/www.honobono-life.info\/wpeng\/angularjs-server-side-grid-paging\/","title":{"rendered":"AngularJS Server side grid Paging"},"content":{"rendered":"<ul>\r\n<li>AngularJS : 1.2.23<\/li>\r\n<li>Bootstrap : 3.x<\/li>\r\n<li>ng-grid : 2.0.13<\/li>\r\n<li>include file<\/li>\r\nng-grid.min.css,jquery.js,angular.min.js,ng-grid.min.js,ui-bootstrap-tpls-0.11.0.min.js\r\n<\/ul>\r\n<!--more-->\r\n<link href=\"http:\/\/www.honobono-life.info\/wpeng\/wp-content\/themes\/ang\/css\/ng-grid.min.css\" rel=\"stylesheet\">\r\n<link href=\"http:\/\/www.honobono-life.info\/wpeng\/wp-content\/themes\/ang\/css\/grid1.css\" rel=\"stylesheet\">\r\n<script type='text\/javascript' src='http:\/\/www.honobono-life.info\/wpeng\/wp-content\/themes\/ang\/js\/angular.min.js'><\/script><script type='text\/javascript' src='http:\/\/www.honobono-life.info\/wpeng\/wp-content\/themes\/ang\/js\/ui-bootstrap-tpls-0.11.0.min.js'><\/script>\r\n<script type='text\/javascript' src='http:\/\/www.honobono-life.info\/wpeng\/wp-content\/themes\/ang\/js\/ng-grid-2.0.13.min.js'><\/script>\r\n<script type='text\/javascript' src='http:\/\/www.honobono-life.info\/wpeng\/wp-content\/themes\/ang\/js\/grid2.js'><\/script>\r\n<div ng-app=\"googleMapApp\" role=\"tabpanel\">\r\n  <ul class=\"nav nav-tabs\">\r\n    <li class=\"active\"><a href=\"#demo1\" data-toggle=\"tab\">demo<\/a><\/li>\r\n    <li><a href=\"#html1\" data-toggle=\"tab\">markup<\/a><\/li>\r\n    <li><a href=\"#script1\" data-toggle=\"tab\">script<\/a><\/li>\r\n    <li><a href=\"#template1\" data-toggle=\"tab\">Server PHP<\/a><\/li>\r\n  <\/ul>\r\n  <div class=\"tab-content\">\r\n    <div class=\"tab-pane active\" id=\"demo1\">\r\n\r\n<div ng-controller=\"MyCtrl2\">\r\n  <div class=\"row\">\r\n    <div class=\"col-sm-12\">\r\n      <div class=\"gridStyle\" ng-grid=\"gridOptions\">\r\n      <\/div>\r\n    <\/div>\r\n  <\/div>\r\n<\/div>\r\n\r\n    <\/div>\r\n    <div class=\"tab-pane\" id=\"html1\">\r\n<pre>\r\n&lt;link href=\"http:\/\/www.example.com\/wp\/wp-content\/themes\/ang\/css\/ng-grid.min.css\" rel=\"stylesheet\">\r\n&lt;link href=\"http:\/\/www.example.com\/wp\/wp-content\/themes\/ang\/css\/grid1.css\" rel=\"stylesheet\">\r\n&lt;script type='text\/javascript' src='http:\/\/www.example.com\/wp\/wp-content\/themes\/ang\/js\/ng-grid.min.js'>&lt;\/script>\r\n&lt;script type='text\/javascript' src='http:\/\/www.example.com\/wp\/wp-content\/themes\/ang\/js\/grid1.js'>&lt;\/script>\r\n&lt;div ng-controller=\"MyCtrl2\">\r\n  &lt;div class=\"row\">\r\n    &lt;div class=\"col-sm-12\">\r\n      &lt;div class=\"gridStyle\" ng-grid=\"gridOptions\">\r\n      &lt;\/div>\r\n    &lt;\/div>\r\n  &lt;\/div>\r\n&lt;\/div>\r\n<\/pre>\r\n    <\/div>\r\n\r\n    <div class=\"tab-pane\" id=\"script1\">\r\n<pre>\r\nvar myApp = angular.module('googleMapApp', ['ui.bootstrap','ngGrid']);\r\n\r\nmyApp.controller('MyCtrl2', function($scope,$http) {\r\n    $scope.pagingOptions = {\r\n      pageSizes: [3, 5, 8],\r\n      pageSize: 3,\r\n      currentPage: 1\r\n    };\r\n    $scope.totalServerItems = 0;\r\n    $scope.setPagingData = function(data,page,pageSize){\r\n      var pagedData = data.slice((page - 1) * pageSize, page * pageSize);\r\n      $scope.myData = pagedData;\r\n      $scope.totalServerItems = data.length;\r\n      if (!$scope.$$phase) {\r\n        $scope.$apply();\r\n      }\r\n    };\r\n    $scope.getPagedDataAsync = function (pageSize, page) {\r\n      setTimeout(function () {\r\n        $http.get('..\/wp-content\/themes\/ang\/json-grid.php').success(function (largeLoad) {\r\n          $scope.setPagingData(largeLoad,page,pageSize);\r\n        });\r\n      }, 100);\r\n    };\r\n    $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions\r\n.currentPage);\r\n\r\n    $scope.$watch('pagingOptions', function (newVal, oldVal) {\r\n      if (newVal !== oldVal && newVal.currentPage !== oldVal.currentPage) {\r\n        $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOpt\r\nions.currentPage);\r\n      }\r\n    }, true);\r\n\r\n    $scope.gridOptions = {\r\n      data: 'myData',\r\n      enablePaging: true,\r\n      showFooter: true,\r\n      totalServerItems: 'totalServerItems',\r\n      pagingOptions: $scope.pagingOptions\r\n    };\r\n\r\n});\r\n<\/pre>\r\n    <\/div><!-- \/.tab-pane -->\r\n\r\n    <div class=\"tab-pane\" id=\"template1\">\r\n<pre>\r\n&lt;?php\r\nrequire(\"dbinfo.php\");\r\n$dsn = 'mysql:host=localhost;dbname='.$database.';charset=utf8';\r\ntry {\r\n  $dbh = new PDO($dsn, $username, $password,array(PDO::ATTR_EMULATE_PREPARES =>\r\nfalse,PDO::MYSQL_ATTR_INIT_COMMAND => \"SET CHARACTER SET `utf8`\"));\r\n} catch (PDOException $e) {\r\n  exit('DB connect error'.$e->getMessage());\r\n}\r\n$st = $dbh->query(\"SELECT * FROM grid_products WHERE 1\");\r\necho json_encode($st->fetchAll(PDO::FETCH_ASSOC));\r\n\r\n?>\r\n<\/pre>\r\n    <\/div><!-- \/.tab-pane -->\r\n\r\n  <\/div><!-- \/.tab-content -->\r\n<\/div><!-- \/.tabpanel -->\r\n","protected":false},"excerpt":{"rendered":"<p>AngularJS : 1.2.23 Bootstrap : 3.x ng-grid : 2.0.13 include file ng-grid.min.css,jquery.js,angular.min.js,ng-grid.min.js,ui-bootstrap-tpls-0.11.0.min.js<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts\/551"}],"collection":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/comments?post=551"}],"version-history":[{"count":6,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":1476,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts\/551\/revisions\/1476"}],"wp:attachment":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/media?parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/categories?post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/tags?post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}