Skip to content

Commit 67b6126

Browse files
authored
Merge branch 'angular-ui:master' into hotfix/4457
2 parents f194b83 + 30c0743 commit 67b6126

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/js/factories/Grid.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,9 @@ angular.module('ui.grid')
686686
* @param {string} name column name
687687
*/
688688
Grid.prototype.getColumn = function getColumn(name) {
689-
var columns = this.columns.filter(function (column) {
689+
return rowColumnFinder(this.columns, function (column) {
690690
return column.colDef.name === name;
691691
});
692-
693-
return columns.length > 0 ? columns[0] : null;
694692
};
695693

696694
/**
@@ -701,10 +699,9 @@ angular.module('ui.grid')
701699
* @param {string} name column.field
702700
*/
703701
Grid.prototype.getColDef = function getColDef(name) {
704-
var colDefs = this.options.columnDefs.filter(function (colDef) {
702+
return rowColumnFinder(this.options.columnDefs, function (colDef) {
705703
return colDef.name === name;
706704
});
707-
return colDefs.length > 0 ? colDefs[0] : null;
708705
};
709706

710707
/**
@@ -1073,6 +1070,25 @@ angular.module('ui.grid')
10731070
return t;
10741071
};
10751072

1073+
var rowColumnFinder = function(array, func) {
1074+
if (array && array.length) {
1075+
if (angular.isFunction(array.find)) {
1076+
return array.find(func) || null;
1077+
}
1078+
1079+
var result = null;
1080+
array.every(function (entry) {
1081+
if (func(entry)) {
1082+
result = entry;
1083+
return false;
1084+
}
1085+
return true;
1086+
});
1087+
return result;
1088+
}
1089+
return null;
1090+
}
1091+
10761092
/**
10771093
* @ngdoc function
10781094
* @name getRow
@@ -1084,13 +1100,10 @@ angular.module('ui.grid')
10841100
*/
10851101
Grid.prototype.getRow = function getRow(rowEntity, lookInRows) {
10861102
var self = this;
1087-
1088-
lookInRows = typeof(lookInRows) === 'undefined' ? self.rows : lookInRows;
1089-
1090-
var rows = lookInRows.filter(function (row) {
1103+
lookInRows = lookInRows == void 0 ? this.rows : lookInRows;
1104+
return rowColumnFinder(lookInRows, function (row) {
10911105
return self.options.rowEquality(row.entity, rowEntity);
10921106
});
1093-
return rows.length > 0 ? rows[0] : null;
10941107
};
10951108

10961109
/**

0 commit comments

Comments
 (0)