Angular實現(xiàn)的table表格排序功能完整示例
更新時間:2017年12月22日 11:08:51 作者:qq_41073714
這篇文章主要介紹了Angular實現(xiàn)的table表格排序功能,結合完整實例形式分析了AngularJS表格排序所涉及的事件響應、元素遍歷、屬性修改等相關操作技巧,需要的朋友可以參考下
本文實例講述了Angular實現(xiàn)的table表格排序功能。分享給大家供大家參考,具體如下:
先來看看效果圖:

完整代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>chabaoo.cn 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:"已發(fā)貨"},
{state1:false,id:3007,name:"iphone6",username:"王紅",tel:18524565588,price:5635,city:"鄭州",time:new Date('11-23 11:38:20'),state:"已發(fā)貨"},
{state1:false,id:5312,name:"iphone7",username:"趙小龍",tel:17545585598,price:6180,city:"北京",time:new Date('11-23 9:17:00'),state:"未發(fā)貨"},
{state1:false,id:2132,name:"iphone8",username:"趙強",tel:17625565618,price:7190,city:"上海",time:new Date('11-23 10:40:00'),state:"未發(fā)貨"}
];
$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=="已發(fā)貨"&&$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="">按狀態(tài)查詢</option>
<option value="已發(fā)貨">已發(fā)貨</option>
<option value="未發(fā)貨">未發(fā)貨</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>狀態(tài)</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=='已發(fā)貨'" style="color: greenyellow;">{{s.state}}</span>
<span ng-show="s.state=='未發(fā)貨'" style="color: yellow;"><a href="#" rel="external nofollow" ng-click="s.state='已發(fā)貨'">{{s.state}}</a></span></td>
</tr>
</table>
<div 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>
</div>
</body>
</html>
更多關于AngularJS相關內容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結》、《AngularJS入門與進階教程》及《AngularJS MVC架構總結》
希望本文所述對大家AngularJS程序設計有所幫助。
您可能感興趣的文章:
- AngularJS模糊查詢功能實現(xiàn)代碼(過濾內容下拉菜單排序過濾敏感字符驗證判斷后添加表格信息)
- AngularJS中table表格基本操作示例
- Angular將填入表單的數(shù)據(jù)渲染到表格的方法
- AngularJS實現(xiàn)表格的增刪改查(僅限前端)
- Angular.js與Bootstrap相結合實現(xiàn)表格分頁代碼
- AngularJS中的Directive自定義一個表格
- 使用angularjs創(chuàng)建簡單表格
- AngularJS表格添加序號的方法
- Angular表格神器ui-grid應用詳解
- AngularJS表格樣式簡單設置方法示例
- Angular實現(xiàn)較為復雜的表格過濾,刪除功能示例
相關文章
在AngularJS中使用jQuery的zTree插件的方法
這篇文章主要介紹了在AngularJS中使用jQuery的zTree插件的方法,Angular中集成了jqLite,但還不是完全版的jQuery,需要的朋友可以參考下2016-04-04
Angular中封裝fancyBox(圖片預覽)遇到問題小結
這篇文章主要介紹了Angular中封裝fancyBox(圖片預覽)遇到的問題小結,需要的朋友可以參考下2017-09-09
Angular 4依賴注入學習教程之Injectable裝飾器(六)
這篇文章主要給大家介紹了關于Angular 4依賴注入之Injectable裝飾器的相關資料,文中介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面來跟著小編一起學習學習吧。2017-06-06
AngularJS數(shù)據(jù)源的多種獲取方式匯總
在AngularJS中獲取數(shù)據(jù)源的方式有很多種,本文給大家整理幾種獲取數(shù)據(jù)源的方式,對angularjs獲取數(shù)據(jù)源的方式相關知識感興趣的朋友一起學習吧2016-02-02
Angular中的ActivatedRoute和Router原理解釋
這篇文章主要為大家介紹了Angular中的ActivatedRoute和Router原理解釋,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-04-04

