Home > Web Front-end > JS Tutorial > body text

How to use Angular to implement the triangular arrow labeling function

亚连
Release: 2018-06-14 16:45:21
Original
1855 people have browsed it

This article mainly introduces the custom fuzzy query, sorting and triangular arrow marking functions implemented by Angular, involving AngularJS's traversal, query, judgment, sorting and other related operation skills for page table elements. Friends in need can refer to the following

The example in this article describes the custom fuzzy query, sorting and triangular arrow labeling functions implemented by Angular. Share it with everyone for your reference, the details are as follows:

Let’s take a look at the running effect first:

The specific code is as follows:

<!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(&#39;name&#39;)">姓名<span ng-class="getClass(&#39;name&#39;)"></span></th>
  <th ng-click="sortFun(&#39;salary&#39;)">薪资<span ng-class="getClass(&#39;salary&#39;)"></span></th>
  <th ng-click="sortFun(&#39;sex&#39;)">性别<span ng-class="getClass(&#39;sex&#39;)"></span></th>
  <th ng-click="sortFun(&#39;birthday&#39;)">生日<span ng-class="getClass(&#39;birthday&#39;)"></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:&#39;$&#39;}}</td>
    <td>{{item.sex}}</td>
    <td>{{item.birthday|date:&#39;yyyy-MM-dd&#39;}}</td>
  </tr>
  </tbody>
</table>
</body>
</html>
Copy after login

Note : There are still some functions in the code that are not perfect enough. Interested friends can improve them by themselves.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to package the koa2 framework app through webpack, how to do it?

Detailed interpretation of Vue component development ideas

Detailed interpretation of how to use components and their functions in Vue.js?

The above is the detailed content of How to use Angular to implement the triangular arrow labeling function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template