我有一个包含Name
,Category
,DocumentName
和Date_generated
列的表格。
DocumentName
应该是辅助排序列,例如,如果我按desc
顺序按名称排序,则documentname应始终按升序排列。排序应该在表格标题点击时发生。
在标题中我提到了列名如下:
ng-click="orderByFieldName=['name','doc_name']; sortOrder=!sortOrder"
并在ng-repeat
中orderBy:orderByFieldName:sortOrder
但现在两者都按升序或降序排序。我们如何才能单独为doc-Name设置默认排序顺序?
答案 0 :(得分:0)
This was achieved using different sortOrder for the fields and based on current sortOrder we toggle the doc_name as shown below:
$scope.customSort = function () {
var docName = 'doc_name';
if (!$scope.sortOrder) {
docName = '-doc_name';
}
if ($scope.orderByFieldName == 1) {
if ($scope.sortFlag == 1) {
$scope.staffNameSortOrder = !$scope.staffNameSortOrder;
}
else {
$scope.staffNameSortOrder = false;
docName = 'doc_name';
$scope.sortFlag = 1;
}
$scope.orderByFieldName = ['staff_name', docName];
$scope.sortOrder = $scope.staffNameSortOrder;
}
else if ($scope.orderByFieldName == 3) {
if ($scope.sortFlag == 3) {
$scope.docNameSortOrder = !$scope.docNameSortOrder;
}
else {
$scope.docNameSortOrder = false;
$scope.sortFlag = 3;
}
$scope.orderByFieldName = ['doc_name'];
$scope.sortOrder = $scope.docNameSortOrder;
}
}
In the ng-repeat you can add orderBy:orderByFieldName:sortOrder