2016년 1월 27일 수요일

[AngularJS] Custom filter - Paging



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
<!doctype html>
<html lng='utf-8'>
  <head>
    <meta charset="utf-8">
    <!--
      <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
    -->
  </head>
  <body ng-app="memberApp">
    <div ng-controller="ListCtrl" class="panel panel-primary">
    <div class="panel-heading">회원 목록 </div>  
    <div class="panel-body" >
    페이지 번호 <input type='text' ng-model='page' >
    <table class=table>
      <tr>
        <th ng-click='criteria ="id"'> id </th>
        <th ng-click='criteria ="name"'> name </th>
        <th ng-click='criteria ="tel"'> tel </th>
      </tr>
      <tr ng-repeat="member in members|paging:page">
        <td> {{member.id}} </th>
        <td> {{member.name}} </th>
        <td> {{member.tel}} </th>
      </tr>
    </table>
    </div>
    </div>  
    </div>
 
    <script src="http://code.angularjs.org/1.2.12/angular.min.js"></script>
    <script>
    var memberApp = angular.module("memberApp", []);
    memberApp.filter('paging'function(){
      return function(array, page) {
        var pageNum = page?(page -1* 100
        return array.slice(pageNum, pageNum + 10);
      }
    });
 
    memberApp.controller("ListCtrl"function($scope){
      $scope.members = [];
      for(var i = 0; i < 121; i++){
        $scope.members.push({"id":"user"+(i + 1),"name":"user"+(i+1), "tel":"123-00"+i});
      }
    });      
    </script>
  </body>
</html>
cs

댓글 없음:

댓글 쓰기