Skip to content

Commit 045b77c

Browse files
Portugal, Marcelomportuga
Portugal, Marcelo
authored andcommitted
fix(sort): add an extra check for sort data
When doing a restore as part of saveState, it is possible to trigger the sort logic without having a sort object, which causes failures.
1 parent a7f5e04 commit 045b77c

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/js/core/directives/ui-grid-header-cell.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
};
4444
$scope.isSortPriorityVisible = function() {
4545
// show sort priority if column is sorted and there is at least one other sorted column
46-
return angular.isNumber($scope.col.sort.priority) && $scope.grid.columns.some(function(element, index) {
46+
return $scope.col && $scope.col.sort && angular.isNumber($scope.col.sort.priority) && $scope.grid.columns.some(function(element, index) {
4747
return angular.isNumber(element.sort.priority) && element !== $scope.col;
4848
});
4949
};
@@ -52,7 +52,7 @@
5252
// Trying to recreate this sort of thing but it was getting messy having it in the template.
5353
// Sort direction {{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending': 'none')}}.
5454
// {{col.sort.priority ? {{columnPriorityText}} {{col.sort.priority}} : ''}
55-
var label = col.sort.direction === uiGridConstants.ASC ? $scope.i18n.sort.ascending : ( col.sort.direction === uiGridConstants.DESC ? $scope.i18n.sort.descending : $scope.i18n.sort.none);
55+
var label = col.sort && col.sort.direction === uiGridConstants.ASC ? $scope.i18n.sort.ascending : ( col.sort && col.sort.direction === uiGridConstants.DESC ? $scope.i18n.sort.descending : $scope.i18n.sort.none);
5656

5757
if ($scope.isSortPriorityVisible()) {
5858
label = label + '. ' + $scope.i18n.headerCell.priority + ' ' + (col.sort.priority + 1);

src/js/core/factories/Grid.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ angular.module('ui.grid')
19691969

19701970
if (!direction) {
19711971
// Find the current position in the cycle (or -1).
1972-
var i = column.sortDirectionCycle.indexOf(column.sort.direction ? column.sort.direction : null);
1972+
var i = column.sortDirectionCycle.indexOf(column.sort && column.sort.direction ? column.sort.direction : null);
19731973
// Proceed to the next position in the cycle (or start at the beginning).
19741974
i = (i+1) % column.sortDirectionCycle.length;
19751975
// If suppressRemoveSort is set, and the next position in the cycle would

src/js/core/services/rowSorter.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
343343
*/
344344
rowSorter.prioritySort = function (a, b) {
345345
// Both columns have a sort priority
346-
if (a.sort.priority !== undefined && b.sort.priority !== undefined) {
346+
if (a.sort && a.sort.priority !== undefined && b.sort && b.sort.priority !== undefined) {
347347
// A is higher priority
348348
if (a.sort.priority < b.sort.priority) {
349349
return -1;
@@ -358,11 +358,11 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
358358
}
359359
}
360360
// Only A has a priority
361-
else if (a.sort.priority !== undefined) {
361+
else if (a.sort && a.sort.priority !== undefined) {
362362
return -1;
363363
}
364364
// Only B has a priority
365-
else if (b.sort.priority !== undefined) {
365+
else if (b.sort && b.sort.priority !== undefined) {
366366
return 1;
367367
}
368368
// Neither has a priority

0 commit comments

Comments
 (0)