我有一个可编辑的 ng-grid。如何向空单元格添加占位符(编辑单元格时它们应该消失)?
我知道输入标签是可能的:
<input type="text" placeholder='Type something here'>
最佳答案
使用editableCellTemplate
。例如:
$scope.gridOptions = {
data: 'myData',
enableCellSelection: true,
enableRowSelection: false,
enableCellEdit: true,
columnDefs: [{
field: 'name',
displayName: 'Name',
enableCellEdit: false
}, {
field: 'age',
enableCellEdit: true,
editableCellTemplate: '<input placeholder="Type something here" ng-input="COL_FIELD" ng-model="COL_FIELD" />'
}]
};
这是一个工作演示:http://plnkr.co/edit/x4Xhd0?p=preview
<小时/>如果您希望在不编辑单元格时占位符文本可见,您可以创建一个自定义(不可编辑)cellTemplate
来显示占位符文本而不是空值:
cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text>{{COL_FIELD || "Type something here"}}</span></div>',
editableCellTemplate: '<input ng-input="COL_FIELD" ng-model="COL_FIELD" placeholder="Type something here"/>'
关于javascript - 将占位符添加到 ng-grid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23355056/