当前位置: 移动技术网 > IT编程>脚本编程>AngularJs > Angular实现的自定义模糊查询、排序及三角箭头标注功能示例

Angular实现的自定义模糊查询、排序及三角箭头标注功能示例

2018年02月13日  | 移动技术网IT编程  | 我要评论

肉蒲团3d版下载,富贵竹养殖方法,吕慎恒

本文实例讲述了angular实现的自定义模糊查询、排序及三角箭头标注功能。分享给大家供大家参考,具体如下:

先来看看运行效果:

具体代码如下:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>www.jb51.net angular模糊查询、排序</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    table{
      border-collapse: collapse;
    }
    td{
      padding: 10px;
      border: 1px solid #000;
    }
    .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 src="angular.min.js"></script>
  <script>
    var myapp=angular.module("myapp",[]);
    myapp.controller("myctrl",function ($scope) {
      var userinfo=[
        {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.arr=userinfo;
      /*自定义的模糊查询*/
      $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 (column) {
        if($scope.sort==column){
          $scope.revers=!$scope.revers;
        }else{
          $scope.revers=false;
        }
        $scope.sort=column;
      };
      $scope.getclass=function(column){
        if($scope.sort==column){
          if($scope.revers==false){
            return "top"
          }else{
            return "bot"
          }
        }
      }
    })
  </script>
</head>
<body ng-app="myapp" ng-controller="myctrl">
<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>
  <tbody>
  <tr ng-repeat="item in arr|filter:searchfun:value|orderby:sort">
    <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>
  </tbody>
</table>
</body>
</html>

注:代码中尚有功能不够完善的部分,感兴趣的朋友可以自行加以完善。

更多关于angularjs相关内容感兴趣的读者可查看本站专题:《angularjs指令操作技巧总结》、《angularjs入门与进阶教程》及《angularjs mvc架构总结

希望本文所述对大家angularjs程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网