Don't talk much, just look at the sample code
HTML code
<th class= "col-md-3" ><a href= "ng-click=" desc (' 2 ', La=!la) "> Unit price </a></th>
<th class=" Col-md-3 "><a href=" "ng-click=" desc (' 3 ', La=!la) "> Sales Amount </a></th>
<th class=" Col-md-1 " ><a href= "" ng-click= "desc (' 4 ', La=!la)" > Sales quantity </a></th>
Which la=!la
is used to determine whether the current click is true
orfalse
JS Code
Start by default the Totalnum field is sorted in descending order $scope. Foodsale =ret.sort (function (x,y) {return y.totalnum-x.totalnum;//This means that according to R Et "means receive return array" Inside the Totalnum field in descending order instead return x.totalnum-y.totalnum; is ascending}) $scope. desc= function (Fla,bol) {if (fla== "4") {if (bol==false) {$scope. Foodsale = $scope. Food
Sale.sort (function (x,y) {return y.totalnum-x.totalnum; }else{Console.log ("BBB") $scope. Foodsale = $scope. Foodsale.sort (function (x,y) {return x.to
Talnum-y.totalnum; }}}else if (fla== "3") {//totalmoney if (bol==false) {$scope. Foodsale = $scope. Foodsale.sort (Function (x,y
) {return y.totalmoney-x.totalmoney; })}else{$scope. Foodsale = $scope. Foodsale.sort (function (x,y) {return x.totalmoney-y.totalmone
Y }}}else if (fla== "2") {//price if (bol==false) {$scope. Foodsale = $scope. Foodsale.sort (Function (x,y ) {return Y.price- X.price;
})}else{$scope. Foodsale = $scope. Foodsale.sort (function (x,y) {return x.price-y.price; }
)
}
}
Summarize
OK, the above is ANGULARJS implementation double-click the entire content of the sorting function, through the above example code can be achieved by double-clicking the order, I hope to learn Angularjs can help.