将占位符添加到ng网格中

Add placeholders to ng-grid

本文关键字:网格 ng 占位符 添加      更新时间:2023-09-26

我有一个可编辑的ng网格。如何向空单元格添加占位符(编辑单元格时占位符应消失)?

我知道这是可能的输入标签:

<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"/>'