angularjs 单列排序+模糊查询

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../angular-1.5.5/angular.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        table{
            border-collapse: collapse;
            margin-top: 10px;
        }
        table td,th{
            border: 1px solid #000000;
        }
        .top{
            display:inline-block;
            width: 0;
            height: 0;
            border: 10px solid transparent;
            border-top: 10px solid red;
        }
        .bot{
            display:inline-block;
            width: 0;
            height: 0;
            border: 10px solid transparent;
            border-bottom: 10px solid red;
        }
    </style>

    <script>
        var app=angular.module("myapp",[]);
        app.controller("mycontroller",function ($scope) {
            $scope.arr=[
                {name:"marry",salary:12345,sex:"girl",birthday:1505111954735},
                {name:"Lily",salary:12425,sex:"girl",birthday:1505711954735},
                {name:"Jeny",salary:87145,sex:"girl",birthday:1505811954735},
                {name:"Rose",salary:23845,sex:"girl",birthday:1905111954735},
                {name:"Tom",salary:86565,sex:"boy",birthday:1575111994735}
            ];
            /*自定义的按照字段查询*/
            $scope.search="";
            $scope.searchFun=function (obj) {
                if($scope.search!=""){
                    if(obj.name.toLowerCase().indexOf($scope.search.toLowerCase())!=-1){
                        return true;
                    }else {
                        return false;
                    }
                }else {
                    return true;
                }
            };
            /*排序功能的实现*/
            $scope.sort="name";
            $scope.revers=false;
            $scope.sortfun=function (colnum) {
                if($scope.sort==colnum){
                    $scope.revers=!$scope.revers;
                }else {
                    $scope.revers=false;
                }
                $scope.sort=colnum;
            };
            /*获取类的方法*/
            $scope.getClass=function (colnum) {
                if ($scope.sort==colnum){
                    if($scope.revers==false){
                        return "top";
                    }else {
                        return "bot";
                    }
                }
            }

        })
    </script>
</head>
<body ng-app="myapp" ng-controller="mycontroller">
<input type="text" ng-model="search">
<table>
    <thead>
    <th>编号</th>
    <th ng-click="sortfun('name')">姓名<span ng-class="getClass('name')"></span></th>
    <th ng-click="sortfun('salary')">薪资<span ng-class="getClass('salary')"></span></th>
    <th ng-click="sortfun('sex')">性别<span ng-class="getClass('sex')"></span></th>
    <th ng-click="sortfun('birthday')">生日<span ng-class="getClass('birthday')"></span></th>
    </thead>
    <tr ng-repeat="item in arr|filter:searchFun:search|orderBy:sort:revers">
        <td>{{$index}}</td>
        <td>{{item.name|uppercase}}</td>
        <td>{{item.salary|currency:'$'}}</td>
        <td>{{item.sex}}</td>
        <td>{{item.birthday|date:'yyyy-mm-dd'}}</td>
    </tr>
</table>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值