diff --git a/components/home/lists/lists-controller.js b/components/home/lists/lists-controller.js index 727d4bd61..79b217777 100644 --- a/components/home/lists/lists-controller.js +++ b/components/home/lists/lists-controller.js @@ -185,12 +185,6 @@ trackerCapture.controller('ListsController',function( } $scope.showCustomWorkingListInline = false; $scope.currentTrackedEntityList = { type: type, config: config, data: data }; - if(!$scope.currentTrackedEntityList.sortColumn){ - $scope.currentTrackedEntityList.sortColumn = { - id: 'created', - direction: 'desc', - } - } } var setCurrentTrackedEntityListData = function(serverResponse){ @@ -201,7 +195,7 @@ trackerCapture.controller('ListsController',function( - $scope.fetchTeis = function(pager, sortColumn){ + $scope.fetchTeis = function(pager){ var s = 1; if($scope.currentTrackedEntityList){ if($scope.currentTrackedEntityList.type === $scope.trackedEntityListTypes.CUSTOM){ @@ -395,11 +389,12 @@ trackerCapture.controller('ListsController',function( sortedTei = sortedTei.concat(data.rows.other); } sortedTei = $filter('orderBy')(sortedTei, function(tei) { + var id = $scope.currentTrackedEntityList.sortColumn ? $scope.currentTrackedEntityList.sortColumn.id : 'created'; if($scope.currentTrackedEntityList.sortColumn && $scope.currentTrackedEntityList.sortColumn.valueType === 'date'){ - var d = tei[$scope.currentTrackedEntityList.sortColumn.id]; + var d = tei[id]; return DateUtils.getDate(d); } - return tei[$scope.currentTrackedEntityList.sortColumn.id]; + return tei[id]; }, $scope.currentTrackedEntityList.direction == 'desc'); angular.forEach(sortedTei, function(tei){ diff --git a/scripts/services.js b/scripts/services.js index e6d55f2cc..fc19d3a52 100644 --- a/scripts/services.js +++ b/scripts/services.js @@ -2746,7 +2746,7 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour } return eventUrl; } - var getCachedMultipleEventFiltersData = function(workingList, pager, sortColumn){ + var getCachedMultipleEventFiltersData = function(workingList, pager){ var cachedData = cachedMultipleEventFiltersData[workingList.name]; if(!pager) pager = { page: 1, pageSize: 50, pageCount: Math.ceil(cachedData.rows.length/50)}; var pageEnd = (pager.pageSize*pager.page); @@ -2793,13 +2793,15 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour existing[d[0]] = true; return true; }); - var sortColumnIndex = data.headers.findIndex(function(h){ return h.name === sortColumn.id}); - if(sortColumnIndex) data.rows = orderByKeyFilter(data.rows, sortColumnIndex, sortColumn.direction); + if (sortColumn) { + var sortColumnIndex = data.headers.findIndex(function(h){ return h.name === sortColumn.id}); + if(sortColumnIndex) data.rows = orderByKeyFilter(data.rows, sortColumnIndex, sortColumn.direction); + } //order list cachedMultipleEventFiltersData[workingList.name] = data; workingList.cachedSorting = searchParams.sortUrl; workingList.cachedOrgUnit = searchParams.orgUnitId; - var data = getCachedMultipleEventFiltersData(workingList, pager, sortColumn); + var data = getCachedMultipleEventFiltersData(workingList, pager); def.resolve(data); }); }