我正在使用AngularJs和ui-grid,在我的网格中我在Name Column中使用auto-complete;说ui-grid-cellNav启用了单元格导航,我的问题是当我在自动完成时上下按箭头时它会改变网格中的行,而不是自动完成的项目:
var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.edit', 'ui.grid.cellNav', 'ui.grid.pinning', 'ui.bootstrap']);
app.controller('MainCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
$scope.gridOptions = {
modifierKeysToMultiSelectCells: true,
showGridFooter: true
};
$scope.gridOptions.columnDefs = [
{ name: 'id', width:'150' },
{
name: 'name',
width:'200',
enableCellEditOnFocus: true,
editableCellTemplate:'<div class="typeaheadcontainer"><input type="text" ' +
'class="typeaheadcontrol"' +
'data-ng-model="MODEL_COL_FIELD" ' +
'data-typeahead="name as states.name for states in grid.appScope.states | filter:$viewValue | limitTo:8" ' +
'data-ng-required="true" ' +
'typeahead-append-to-body="true"'+
'data-typeahead-editable ="false"' +
'ui-grid-editor ui-grid-edit' +
'data-typeahead-on-select="typeaheadSelected(row.entity, $item)" ' +
'/></div>',
},
{ name: 'age', displayName: 'Age (not focusable)', allowCellFocus : false, width:'100' },
{ name: 'address.city', width:'200' },
{ name: 'phone', width:'150' },
{ name: 'company', width:'150' },
{ name: 'email', width:'150' },
{ name: 'balance', width:'100' },
{ name: 'guid', width:'100' }
];
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
.success(function(data) {
$scope.gridOptions.data = data;
});
$scope.info = {};
$scope.currentFocused = "";
$scope.getCurrentFocus = function(){
var rowCol = $scope.gridApi.cellNav.getFocusedCell();
if(rowCol !== null) {
$scope.currentFocused = 'Row Id:' + rowCol.row.entity.id + ' col:' + rowCol.col.colDef.name;
}
};
$scope.getCurrentSelection = function() {
var values = [];
var currentSelection = $scope.gridApi.cellNav.getCurrentSelection();
for (var i = 0; i < currentSelection.length; i++) {
values.push(currentSelection[i].row.entity[currentSelection[i].col.name])
}
$scope.printSelection = values.toString();
};
$scope.scrollTo = function( rowIndex, colIndex ) {
$scope.gridApi.core.scrollTo( $scope.gridOptions.data[rowIndex], $scope.gridOptions.columnDefs[colIndex]);
};
$scope.scrollToFocus = function( rowIndex, colIndex ) {
$scope.gridApi.cellNav.scrollToFocus( $scope.gridOptions.data[rowIndex], $scope.gridOptions.columnDefs[colIndex]);
};
$scope.gridOptions.onRegisterApi = function(gridApi){
$scope.gridApi = gridApi;
gridApi.cellNav.on.navigate($scope,function(newRowCol, oldRowCol){
// var rowCol = {row: newRowCol.row.index, col:newRowCol.col.colDef.name};
// var msg = 'New RowCol is ' + angular.toJson(rowCol);
// if(oldRowCol){
// rowCol = {row: oldRowCol.row.index, col:oldRowCol.col.colDef.name};
// msg += ' Old RowCol is ' + angular.toJson(rowCol);
// }
$log.log('navigation event');
});
};
$scope.states = [
{
"id": 1,
"name": "Alabama",
"abbreviation": "AL"
},
{
"id": 2,
"name": "Alaska",
"abbreviation": "AK"
},
{
"id": 3,
"name": "American Samoa",
"abbreviation": "AS"
},
{
"id": 4,
"name": "Arizona",
"abbreviation": "AZ"
}];
}]);
.grid {
width: 500px;
height: 400px;
}
.printSelection {
width: 600px;
margin-top: 10px;
}
<!doctype html>
<html ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
<script src="http://ui-grid.info/release/ui-grid.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div ng-controller="MainCtrl">
<button type="button" class="btn btn-success" ng-click="scrollTo(20,0)">Scroll To Row 20</button>
<button type="button" class="btn btn-success" ng-click="scrollTo(0,7)">Scroll To Balance</button>
<button type="button" class="btn btn-success" ng-click="scrollTo(50,7)">Scroll To Row 50, Balance</button>
<button type="button" class="btn btn-success" ng-click="scrollToFocus(50,7)">Focus Row 50, Balance</button>
<button type="button" class="btn btn-success" ng-click="getCurrentFocus()">Get Current focused cell</button> <span ng-bind="currentFocused"></span>
<button type="button" class="btn btn-success" ng-click="getCurrentSelection()">Get Current focused cell values</button>
<input type="text" ng-model="printSelection" placeholder="Click the 'Get current focused cell values' button to print cell values of selection here" class="printSelection">
<br>
<br>
<div ui-grid="gridOptions" ui-grid-cellNav ui-grid-pinning ui-grid-edit class="grid"></div>
</div>
<script src="app.js"></script>
</body>
</html>
这是plunker。