Angular實(shí)現(xiàn)的table表格排序功能完整示例
本文實(shí)例講述了Angular實(shí)現(xiàn)的table表格排序功能。分享給大家供大家參考,具體如下:
先來看看效果圖:

完整代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>www.dbjr.com.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:"趙強(qiáng)",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("手機(jī)號(hào)不能為空");
$("#t").css("border-color","red");
}else if(sprice==undefined || sprice==""){
alert("價(jià)格不能為空");
$("#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="按手機(jī)號(hào)查詢" 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>手機(jī)號(hào)</td>
<td>價(jià)格<button ng-click="px='price';flag=!flag" style="background-color: greenyellow;">排序</button></td>
<td>城市</td>
<td>下單時(shí)間<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 />
手機(jī)號(hào):<input type="text" ng-model="stel" id="t"/><br /><br />
價(jià)格為:<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>
更多關(guān)于AngularJS相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結(jié)》、《AngularJS入門與進(jìn)階教程》及《AngularJS MVC架構(gòu)總結(jié)》
希望本文所述對(duì)大家AngularJS程序設(shè)計(jì)有所幫助。
- AngularJS模糊查詢功能實(shí)現(xiàn)代碼(過濾內(nèi)容下拉菜單排序過濾敏感字符驗(yàn)證判斷后添加表格信息)
- AngularJS中table表格基本操作示例
- Angular將填入表單的數(shù)據(jù)渲染到表格的方法
- AngularJS實(shí)現(xiàn)表格的增刪改查(僅限前端)
- Angular.js與Bootstrap相結(jié)合實(shí)現(xiàn)表格分頁(yè)代碼
- AngularJS中的Directive自定義一個(gè)表格
- 使用angularjs創(chuàng)建簡(jiǎn)單表格
- AngularJS表格添加序號(hào)的方法
- Angular表格神器ui-grid應(yīng)用詳解
- AngularJS表格樣式簡(jiǎn)單設(shè)置方法示例
- Angular實(shí)現(xiàn)較為復(fù)雜的表格過濾,刪除功能示例
相關(guān)文章
在AngularJS中使用jQuery的zTree插件的方法
這篇文章主要介紹了在AngularJS中使用jQuery的zTree插件的方法,Angular中集成了jqLite,但還不是完全版的jQuery,需要的朋友可以參考下2016-04-04
Angular中封裝fancyBox(圖片預(yù)覽)遇到問題小結(jié)
這篇文章主要介紹了Angular中封裝fancyBox(圖片預(yù)覽)遇到的問題小結(jié),需要的朋友可以參考下2017-09-09
Angular 4依賴注入學(xué)習(xí)教程之Injectable裝飾器(六)
這篇文章主要給大家介紹了關(guān)于Angular 4依賴注入之Injectable裝飾器的相關(guān)資料,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來跟著小編一起學(xué)習(xí)學(xué)習(xí)吧。2017-06-06
Angular4學(xué)習(xí)教程之HTML屬性綁定的方法
這篇文章主要給大家介紹了關(guān)于Angular4學(xué)習(xí)教程之HTML屬性綁定的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-01-01
AngularJS數(shù)據(jù)源的多種獲取方式匯總
在AngularJS中獲取數(shù)據(jù)源的方式有很多種,本文給大家整理幾種獲取數(shù)據(jù)源的方式,對(duì)angularjs獲取數(shù)據(jù)源的方式相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-02-02
Angular中的ActivatedRoute和Router原理解釋
這篇文章主要為大家介紹了Angular中的ActivatedRoute和Router原理解釋,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04

