angular.module('app', ['ui.grid', 'ui.grid.edit', 'ui.select'])
.controller('MainCtrl', MainCtrl)
.directive('uiSelectWrap', uiSelectWrap);
MainCtrl.$inject = ['$scope', '$http'];
function MainCtrl($scope, $http) {
$scope.gridOptions = {
rowHeight: 38,
columnDefs: [
{ name: 'name' },
{ name: 'age', type: 'number' },
{
name: 'gender',
editableCellTemplate: 'uiSelect',
editDropdownOptionsArray: [
'male',
'female',
'other'
]
}
]
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/v3.0.7/data/500_complex.json')
.success(function(data) {
$scope.gridOptions.data = data;
});
}
uiSelectWrap.$inject = ['$document', 'uiGridEditConstants'];
function uiSelectWrap($document, uiGridEditConstants) {
return function link($scope, $elm, $attr) {
$document.on('click', docClick);
function docClick(evt) {
if ($(evt.target).closest('.ui-select-container').size() === 0) {
$scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
$document.off('click', docClick);
}
}
};
}
body {
padding: 20px;
}
.grid {
width: 600px;
height: 250px;
}
.ui-grid-cell {
overflow: visible;
z-index: 99999;
}
.ui-grid-cell, ui-select-wrap {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<!DOCTYPE html>
<html ng-app="app">
<head>
<link data-require="bootstrap@*" data-semver="3.3.2" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script data-require="jquery@2.1.3" data-semver="2.1.3" src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js"></script>
<link data-require="ui-select@0.11.1" data-semver="0.11.1" rel="stylesheet" href="https://cdn.rawgit.com/angular-ui/ui-select/v0.11.2/dist/select.css" />
<script data-require="ui-select@0.11.1" data-semver="0.11.1" src="https://cdn.rawgit.com/angular-ui/ui-select/v0.11.2/dist/select.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.default.css">
<script src="https://cdn.rawgit.com/angular-ui/ui-grid.info/v3.0.7/release/3.0.7/ui-grid.min.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/angular-ui/ui-grid.info/v3.0.7/release/3.0.7/ui-grid.min.css" type="text/css" />
<link rel="stylesheet" href="main.css" type="text/css" />
</head>
<body>
<div ng-controller="MainCtrl">
<div ui-grid="gridOptions" ui-grid-edit="" class="grid"></div>
</div>
<script type="text/ng-template" id="uiSelect">
<ui-select-wrap>
<ui-select ng-model="MODEL_COL_FIELD" theme="selectize" ng-disabled="disabled" append-to-body="true">
<ui-select-match placeholder="Choose...">{{ COL_FIELD }}</ui-select-match>
<ui-select-choices repeat="item in col.colDef.editDropdownOptionsArray | filter: $select.search">
<span>{{ item }}</span>
</ui-select-choices>
</ui-select>
</ui-select-wrap>
</script>
<script src="app.js"></script>
</body>
</html>
<ui-select-wrap>
<ui-select ng-model="MODEL_COL_FIELD" theme="selectize" ng-disabled="disabled" append-to-body="true">
<ui-select-match placeholder="Choose...">{{ COL_FIELD }}</ui-select-match>
<ui-select-choices repeat="item in col.colDef.editDropdownOptionsArray | filter: $select.search">
<span>{{ item }}</span>
</ui-select-choices>
</ui-select>
</ui-select-wrap>