=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js 2015-04-09 13:20:27 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js 2015-04-14 12:20:55 +0000 @@ -171,6 +171,7 @@ .controller('AddRelationshipController', function($scope, $rootScope, + DateUtils, CurrentSelection, OperatorFactory, AttributesFactory, @@ -264,6 +265,7 @@ $scope.queryUrl = null; $scope.programUrl = null; $scope.attributeUrl = {url: null, hasValue: false}; + $scope.sortColumn = {}; } //listen for selections @@ -272,6 +274,29 @@ $scope.teiForRelationship = relationshipInfo.tei; }); + //sortGrid + $scope.sortGrid = function(gridHeader){ + if ($scope.sortColumn && $scope.sortColumn.id === gridHeader.id){ + $scope.reverse = !$scope.reverse; + return; + } + $scope.sortColumn = gridHeader; + if($scope.sortColumn.valueType === 'date'){ + $scope.reverse = true; + } + else{ + $scope.reverse = false; + } + }; + + $scope.d2Sort = function(tei){ + if($scope.sortColumn && $scope.sortColumn.valueType === 'date'){ + var d = tei[$scope.sortColumn.id]; + return DateUtils.getDate(d); + } + return tei[$scope.sortColumn.id]; + }; + $scope.search = function(mode){ resetFields(); @@ -338,7 +363,12 @@ //process tei grid $scope.trackedEntityList = TEIGridService.format(data,false, $scope.optionSets); $scope.showTrackedEntityDiv = true; - $scope.teiFetched = true; + $scope.teiFetched = true; + + if(!$scope.sortColumn.id){ + $scope.sortGrid({id: 'created', name: $translate('registration_date'), valueType: 'date', displayInListNoProgram: false, showFilter: false, show: false}); + } + }); };