我正在尝试对Angular中的列表进行排序,但是它不起作用。
默认排序顺序应按会计年度降序排列,但某些2019年值将在2020年值之后进行排序:
https://i.imgur.com/1F9JM2V.png
然后,当您单击该列排序时,数字排序不正确:
https://i.imgur.com/67fMJ8V.png
并且结束日期没有排序结构。我在视图中将其设置为MM / dd / yyyy格式,不确定是否有影响:
https://i.imgur.com/dOcnFBt.png
仅尝试反向和降序。不知道是否有任何语法或内置的排序方式。
控制器:
function init() {
$scope.loading = true;
$scope.rfrorder = {
Orderby: 'rfrFY',
descending: false
};
ContractsService.getRefRFRInformation()
.then(function (results) {
$scope.refRFRInfo = results.data;
angular.forEach($scope.refRFRInfo, function (value) {
value.edit = true;
value.editMode = false;
if (value.endDate == null) {
value.edit = false;
}
});
$scope.loading = false;
});
}
$scope.rfrSorting = function (column) {
var sort = $scope.rfrorder;
if (sort.Orderby == column) {
sort.descending = !$scope.rfrorder.descending;
} else {
sort.Orderby = column;
sort.descending = false;
}
};
$scope.rfrselected = function (column) {
if (column == $scope.rfrorder.Orderby) {
return ('tablesort-icon glyphicon glyphicon-arrow-' + (($scope.rfrorder.descending) ? 'down' : 'up'));
}
else {
return 'tablesort-icon glyphicon glyphicon-sort';
}
};
查看:
<thead class="headercolor">
<tr class="thead">
<th ng-click="rfrSorting('rfrFY')"><div class="tablesort-header">RFR FY <i ng-class="rfrselected('rfrFY')"></i></div></th>
<th ng-click="rfrSorting('rfrNumber')"><div class="tablesort-header">RFR Number <i ng-class="rfrselected('rfrNumber')"></i></div></th>
<th ng-click="rfrSorting('rfrEffectiveDate')"><div class="tablesort-header">Effective Date <i ng-class="rfrselected('rfrEffectiveDate')"></i></div></th>
<th ng-click="rfrSorting('rfrEndDate')"><div class="tablesort-header">End Date <i ng-class="rfrselected('rfrEndDate')"></i></div></th>
<th ng-click="rfrSorting('rfrModifiedDate')"><div class="tablesort-header">Modified Date <i ng-class="rfrselected('rfrModifiedDate')"></i></div></th>
<th ng-click="rfrSorting('rfrModifiedBy')"><div class="tablesort-header">Modified By <i ng-class="rfrselected('rfrModifiedBy')"></i></div></th>
<th></th>
</tr>
</thead>
<tbody class="form-group form-group-sm">
<tr ng-repeat-start="rfrDetail in refRFRInfo | orderBy:rfrorder.Orderby:rfrorder.descending">
编辑
我认为这与以字符串形式返回的数字有关。我正在尝试找到一种方法来处理和转换数字,然后将其放回可以显示在视图中的对象中。
ContractsService.getRefRFRInformation()
.then(function (results) {
$scope.refRFRInfo = results.data;
angular.forEach($scope.refRFRInfo, function (value) {
//$scope.model.refRFRInfo.rfrNumber = parseInt(value.rfrNumber);
//$scope.model.refRFRInfo.rfrFY = parseInt(value.rfrFY);
//$scope.model.refRFRInfo.endDate = Date.parse(value.endDate);
$scope.number.push(value.rfrNumber);
value.edit = true;
value.editMode = false;
//new Date(value.startDate).withoutTime() <= new Date().withoutTime() &&
if (value.endDate == null) {
// value.editMode = true;
value.edit = false;
}
});
$scope.loading = false;
});
我了解基本原理,因为我有$ scope.number来进行验证,但是我不知道如何遍历整个对象,然后创建具有适当值的新对象。