This article mainly introduces the table sorting function implemented by Angular, and analyzes the event response, element traversal, attribute modification and other related operation skills involved in AngularJS table sorting in the form of a complete example. Friends in need can refer to the following
The example in this article describes the table sorting function implemented by Angular. Share it with everyone for your reference, the details are as follows:
Let’s take a look at the renderings first:
The complete code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>www.jb51.net Angular表格排序</title> <style> table{ border: 1px solid; text-align: center; width: 40%; height: 400px; } tr,td{ border: 1px solid; } tr:nth-child(2n){ background: gainsboro; } </style> <script type="text/javascript" src="js/angular.min.js" ></script> <script type="text/javascript" src="js/jquery-1.9.1.min.js" ></script> <script> var app=angular.module("MyApp",[]); app.controller("demoC",["$scope",function($scope){ $scope.shop=[{ state1:false,id:9001,name:"iphoneX",username:"张三",tel:13525565588,price:8699,city:"北京",time:new Date('11-23 10:00:00'),state:"已发货"}, {state1:false,id:3007,name:"iphone6",username:"王红",tel:18524565588,price:5635,city:"郑州",time:new Date('11-23 11:38:20'),state:"已发货"}, {state1:false,id:5312,name:"iphone7",username:"赵小龙",tel:17545585598,price:6180,city:"北京",time:new Date('11-23 9:17:00'),state:"未发货"}, {state1:false,id:2132,name:"iphone8",username:"赵强",tel:17625565618,price:7190,city:"上海",time:new Date('11-23 10:40:00'),state:"未发货"} ]; $scope.ckAll=function(){ for(var i in $scope.shop){ $scope.shop[i].state1=$scope.ckall; } } $scope.del=function(){ for(var i=0; i<$scope.shop.length; i++){ if($scope.shop[i].state=="已发货"&&$scope.shop[i].state){ $scope.shop.splice(i,1); i--; } } } $scope.add=function(){ var sname=$scope.sname; var susername=$scope.susername; var stel=$scope.stel; var sprice=$scope.sprice; var scity=$scope.scity; if(sname==undefined || sname==""){ alert("用户名不能为空"); $("#s").css("border-color","red"); }else if(susername==undefined || susername==""){ alert("商品名不能为空"); $("#y").css("border-color","red"); }else if(stel==undefined || stel==""){ alert("手机号不能为空"); $("#t").css("border-color","red"); }else if(sprice==undefined || sprice==""){ alert("价格不能为空"); $("#p").css("border-color","red"); }else if(scity==undefined || scity==""){ alert("城市必须选择"); } else{ $scope.shop.push({name:sname,username:susername,tel:stel,price:sprice,city:scity}) $scope.toto=false; } } }]) </script> </head> <body ng-app="MyApp" ng-controller="demoC"> <button ng-click="toto=true" style="background-color: greenyellow;">新增订单</button> <button ng-click="del()" style="background-color: greenyellow;">批量删除</button> <input type="text" placeholder="按商品名称查询" ng-model="selname" /> <input type="text" placeholder="按手机号查询" ng-model="seltel"/> <select ng-model="selstate"> <option value="">按状态查询</option> <option value="已发货">已发货</option> <option value="未发货">未发货</option> </select> <table cellpadding="0px" cellspacing="0px"> <tr style="background-color: gray;"> <td><input type="checkbox" ng-model="ckall" ng-click="ckAll()"></td> <td>id<button ng-click="px='id';flag=!flag" style="background-color: greenyellow;">排序</button></td> <td>商品名</td> <td>用户名</td> <td>手机号</td> <td>价格<button ng-click="px='price';flag=!flag" style="background-color: greenyellow;">排序</button></td> <td>城市</td> <td>下单时间<button ng-click="px='time';flag=!flag" style="background-color: greenyellow;">排序</button></td> <td>状态</td> </tr> <tr ng-repeat="s in shop | filter:{name:selname} | filter:{tel:seltel} | filter:{state:selstate} | orderBy:px:flag "> <td><input type="checkbox" ng-model="s.state1"></td> <td>{{s.id}}</td> <td>{{s.name}}</td> <td>{{s.username}}</td> <td>{{s.tel}}</td> <td>{{s.price | currency:"¥"}}</td> <td>{{s.city}}</td> <td>{{s.time | date : 'MM-HH hh:dd:ss'}}</td> <td><span ng-show="s.state=='已发货'" style="color: greenyellow;">{{s.state}}</span> <span ng-show="s.state=='未发货'" style="color: yellow;"><a href="#" rel="external nofollow" ng-click="s.state='已发货'">{{s.state}}</a></span></td> </tr> </table> <p style="margin-top: 50px; margin-left: 100px;"> <form ng-show="toto"> 商品名:<input type="text" / ng-model="sname" id="s"><br /><br /> 用户名:<input type="text" ng-model="susername"id="y"/><br /><br /> 手机号:<input type="text" ng-model="stel" id="t"/><br /><br /> 价格为:<input type="text" ng-model="sprice" id="p"/><br /><br /> 城市:<select ng-model="scity"> <option value="">--选择城市--</option> <option value="北京">北京</option> <option value="上海">上海</option> <option value="郑州">郑州</option> </select><br /><br /> <button ng-click="add()">保存</button> </form> </p> </body> </html>
Above I compiled it for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Commonly used components and framework structures in vue (detailed tutorial)
How to solve tap" in fastclick code Click through”
How to implement animated checkboxes in animation.js
How to implement Parcel.js Vue 2.x Achieve extremely fast zero-configuration packaging
The problem that the browser cannot trigger beforeRouteLeave when using Vue
How to implement table paging in vue element
How to implement the recording and playback functions in the WeChat applet
Nuxt.js framework (detailed tutorial)
How to implement a rolling digital clock in JS CSS
The above is the detailed content of How to implement table sorting in Angular. For more information, please follow other related articles on the PHP Chinese website!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor
