2016년 1월 26일 화요일

[AngularJS] Drop down Filter


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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!doctype html>
<html ng-app 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>
<div ng-controller="Ctrl" class="panel panel-primary">
    <div class="panel-heading">Dropdown Filter </div>
    <div class="panel-body">
 
        <select ng-model='type' ng-change="changeSearch(type)">
            <option vlaue="id" >id</option>
            <option vlaue="name">name</option>
            <option vlaue="years">years</option>
        </select>
 
        <input type='text' ng-model='search[type]'/>
 
        <p>{{search}}</p>
 
        <table class=table>
            <tr>
                <th ng-click='criteria ="id"'> id </th>
                <th ng-click='criteria ="name"'> name </th>
                <th ng-click='criteria ="years"'> year </th>
            </tr>
 
            <tr ng-repeat='member in members|filter:search|orderBy:criteria' >
                <td> {{member.id}} </td>
                <td > {{member.name}} </td>
                <td> {{member.years}} </td>
            </tr>
        </table>
 
    </div>
</div>
</div>
<script src="http://code.angularjs.org/1.2.12/angular.min.js"></script>
<script>
 
    function Ctrl($scope){
        $scope.members = [
            {"id":"user00""name":"AAB""years""52"},
            {"id":"user01""name":"BB1""years""46"},
            {"id":"user02""name":"BB2""years""1"},
            {"id":"user03""name":"CCC""years""2"},
            {"id":"user04""name":"CCD""years""2"},
            {"id":"user05""name":"FFF""years""32"},
            {"id":"user06""name":"GGG""years""2"}
        ];
 
        $scope.criteria = $scope.criteria|"id";
 
        $scope.search = {"id":"""name":"""years":"", $:""};
 
 
        $scope.changeSearch = function(type) {
 
            forvar prop in $scope.search){
 
                console.log(prop);
 
                if(prop !== type){
                    $scope.search[prop] = "";
                }
            }
 
        };
    }
</script>
</body>
</html>
cs

댓글 없음:

댓글 쓰기