【发布时间】:2018-08-30 05:31:26
【问题描述】:
我有一个使用ui-grid-cellNav 定义的 Angular-UI 网格,允许在单击时编辑单元格,以及一个自定义模板,用于在特定列前显示 Angular-UI Bootstrap 类型,如下所示:
index.html:
<head>
<script type="text/ng-template" id="TypeaheadTemplate.html">
<div style="height:100%">
<input ng-class="'colt' + col.uid" type="text" class="typeahead form-control" ng-model="MODEL_COL_FIELD"
uib-typeahead="name as item.name for item in grid.appScope.items | filter:$viewValue"
typeahead-editable="false"
typeahead-on-select="grid.appScope.typeaheadSelected(row.entity, $item)"></input>
</div>
</script>
</head>
<body ng-controller="MainCtrl">
<div ui-grid="gridOptions" ui-grid-edit ui-grid-cellNav></div>
</body>
controller.js
app.controller('MainCtrl', function($scope) {
$scope.items = [
{
id: 1,
name: "Item 1",
description: "Example Item #1"
},
{
id: 2,
name: "Item 2",
description: "Example Item #2"
}];
$scope.data = [{}, {}, {}]
$scope.columns = [
{
displayName: "Item",
field: "item.name",
editableCellTemplate: "TypeaheadTemplate.html",
cellTemplate: "TypeaheadTemplate.html",
enableCellEdit: true,
enableCellEditOnFocus: true
},
{
displayName: "Note",
name: "activityId",
enableCellEdit: true,
enableCellEditOnFocus: true
}]
$scope.gridOptions = {
data: $scope.data,
enableRowSelection: false,
showColumnFooter: true,
multiSelect: false,
enableSorting: false,
enableFiltering: false,
gridMenuShowHideColumns: false,
enableColumnMenus: false,
enableCellEditOnFocus: true,
minRowsToShow: 4,
columnDefs: $scope.columns
};
$scope.typeaheadSelected = function(entity, selectedItem) {
entity.item = selectedItem;
}
});
这很好用,ui-grid-cellNav 允许在 Notes 列上单击编辑,并且在 Items 列中进行预输入功能。但是,最初单击网格中的预输入文本框会使文本框模糊,直到再次单击它,并且保持 Notes 中的单元格处于选中状态(但不可编辑)通常会阻止文本框被选中。因此,虽然它功能齐全,但存在一些可用性问题。
我已经尝试使用ng-class 属性手动将类应用到文本框,认为有一些幕后逻辑将元素集中在这个类上,但无济于事。我在 API 文档中也找不到任何建议能够覆盖给定列的 cellNav 行为的内容。删除 ui-grid-cellNav 指令修复了预先输入的焦点,但也破坏了单击编辑。
有没有办法让 Angular-UI 网格中的预输入与 ui-grid-cellNav 很好地配合?
【问题讨论】:
标签: angularjs angular-ui-bootstrap angular-ui-grid angular-ui-typeahead