@@ -686,11 +686,9 @@ angular.module('ui.grid')
686
686
* @param {string } name column name
687
687
*/
688
688
Grid . prototype . getColumn = function getColumn ( name ) {
689
- var columns = this . columns . filter ( function ( column ) {
689
+ return rowColumnFinder ( this . columns , function ( column ) {
690
690
return column . colDef . name === name ;
691
691
} ) ;
692
-
693
- return columns . length > 0 ? columns [ 0 ] : null ;
694
692
} ;
695
693
696
694
/**
@@ -701,10 +699,9 @@ angular.module('ui.grid')
701
699
* @param {string } name column.field
702
700
*/
703
701
Grid . prototype . getColDef = function getColDef ( name ) {
704
- var colDefs = this . options . columnDefs . filter ( function ( colDef ) {
702
+ return rowColumnFinder ( this . options . columnDefs , function ( colDef ) {
705
703
return colDef . name === name ;
706
704
} ) ;
707
- return colDefs . length > 0 ? colDefs [ 0 ] : null ;
708
705
} ;
709
706
710
707
/**
@@ -1073,6 +1070,25 @@ angular.module('ui.grid')
1073
1070
return t ;
1074
1071
} ;
1075
1072
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
+
1076
1092
/**
1077
1093
* @ngdoc function
1078
1094
* @name getRow
@@ -1084,13 +1100,10 @@ angular.module('ui.grid')
1084
1100
*/
1085
1101
Grid . prototype . getRow = function getRow ( rowEntity , lookInRows ) {
1086
1102
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 ) {
1091
1105
return self . options . rowEquality ( row . entity , rowEntity ) ;
1092
1106
} ) ;
1093
- return rows . length > 0 ? rows [ 0 ] : null ;
1094
1107
} ;
1095
1108
1096
1109
/**
0 commit comments