在我的数据库中,日期排列如下(日/月/年)
Date
-----------
10/12/2014
22/10/2014
14/12/2015
我正在使用 angularjs 模板并尝试对日期字段进行排序(使用月份和年份进行排序)如下:
Date
-----------
14/12/2015
10/12/2014
22/10/2014
但它正在排序上升 as
Date
-----------
10/12/2014
14/12/2015
22/10/2014
下降 as
Date
----------
22/10/2014
14/12/2015
10/12/2014
这是我的代码
<div class="row">
<div class="col-md-12" ng-show="filteredItems > 0">
<table class="table table-striped table-bordered">
<thead>
<th>Date <a ng-click="sort_by('time_stamp');"><i class="glyphicon glyphicon-sort"></i></a></th>
<th>Reference number <a ng-click="sort_by('tran_id');"><i class="glyphicon glyphicon-sort"></i></a></th>
</thead>
<tbody>
<tr ng-repeat="data in filtered = (list | filter:search | orderBy : predicate :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">
<td>{{data.time_stamp}}</td>
<td>{{data.tran_id}}</td>
</tr>
</tbody>
</table>
</div>
控制器.js
var app = angular.module('myApp', ['ui.bootstrap']);
app.filter('startFrom', function() {
return function(input, start) {
if(input) {
start = +start; //parse to int
return input.slice(start);
}
return [];
}
});
app.controller('customersCrtl', function ($scope, $http, $timeout) {
$http.get('ajax/getCustomers.php').success(function(data){
$scope.list = data;
$scope.currentPage = 1; //current page
$scope.entryLimit = 5; //max no of items to display in a page
$scope.filteredItems = $scope.list.length; //Initially for no filter
$scope.totalItems = $scope.list.length;
});
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
$scope.filter = function() {
$timeout(function() {
$scope.filteredItems = $scope.filtered.length;
}, 10);
};
$scope.sort_by = function(predicate) {
$scope.predicate = predicate;
$scope.reverse = !$scope.reverse;
};
});
获取客户.php:
$query="select tran_id,tran_type,sender,receiver,amount,fee,DATE_FORMAT(time_stamp, '%d/%m/%Y') as time_stamp,status from transaction where sender ='[email protected] /cdn-cgi/l/email-protection' or receiver ='[email protected] /cdn-cgi/l/email-protection' order by time_stamp DESC";
//$query="select * from transaction";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$arr = array();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$arr[] = $row;
}
}
# JSON-encode the response
$json_response = json_encode($arr);
// # Return the response
echo $json_response;
如何获得我想要的排序