Key code: HTML
<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)"> Number of sales </a> </ th>
Where La=!la is used to determine whether the current click is True or False
JS Code
// The default is the totalnum field in descending order
$ scope.foodsale = ret.sort (function (x, y)
{
return y.totalnum-x.totalnum; // This means according to the totalnum field in ret [receives the returned array] in descending order, otherwise return x.totalnum-y.totalnum; ascending order
})
$ scope.desc = function (fla, bol) {
if (fla == "4") {
if (bol == false) {
$ scope.foodsale = $ scope.foodsale.sort (function (x, y)
{
return y.totalnum-x.totalnum;
})
} else {
console.log ("bbb")
$ scope.foodsale = $ scope.foodsale.sort (function (x, y)
{
return x.totalnum-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.totalmoney;
}
)
}
} 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;
}
)
}
}
The above code can realize double-click sorting
AngularJS implementing double-click Sorting