Angular UI-Grid Header 单元格模板

Angular UI-Grid Header Cell Template

如何设置 header 文本和自定义样式,保持排序和过滤功能不变。

例如:

headerCellTemplate: '<div>Stone Id <b style='color: red'>*</b></div>'

这是我的笨蛋:http://plnkr.co/edit/vy4DjRuoZ48Ced0KfWRV?p=preview

谢谢。

在这里您可以找到 ui-grid header 的默认模板:default header cell template

所以你唯一要做的就是随心所欲地改变。这是一个你想要实现的目标:http://plnkr.co/edit/i9EFvGecvJJD9LKUBbwT?p=preview

$scope.gridOptions = {
    columnDefs: [{
      displayName: 'Name',
      field: 'name',
      headerCellFilter: 'translate',
      headerCellTemplate: 'customTemplate.html',
      enableSorting: true,

    }, {
      displayName: 'GENDER',
      field: 'gender',
      headerCellFilter: 'translate'
    }, {
      displayName: 'COMPANY',
      field: 'company',
      headerCellFilter: 'translate',
      enableFiltering: false
    }]
  };

自定义 header 单元格模板

<div
  role="columnheader"
  ng-class="{ 'sortable': sortable, 'ui-grid-header-cell-last-col': isLastCol }"
  ui-grid-one-bind-aria-labelledby-grid="col.uid + '-header-text ' + col.uid + '-sortdir-text'"
  aria-sort="{{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending' : (!col.sort.direction ? 'none' : 'other'))}}">
  <div
    role="button"
    tabindex="0"
    ng-keydown="handleKeyDown($event)"
    class="ui-grid-cell-contents ui-grid-header-cell-primary-focus"
    col-index="renderIndex"
    title="TOOLTIP">
    <span
      class="ui-grid-header-cell-label"
      ui-grid-one-bind-id-grid="col.uid + '-header-text'">
      {{ col.displayName CUSTOM_FILTERS }}<b style='color: red'>*</b>
    </span>
    <span
      ui-grid-one-bind-id-grid="col.uid + '-sortdir-text'"
      ui-grid-visible="col.sort.direction"
      aria-label="{{getSortDirectionAriaLabel()}}">
      <i
       ng-class="{ 'ui-grid-icon-up-dir': col.sort.direction == asc, 'ui-grid-icon-down-dir': col.sort.direction == desc, 'ui-grid-icon-blank': !col.sort.direction }"
       title="{{isSortPriorityVisible() ? i18n.headerCell.priority + ' ' + ( col.sort.priority + 1 )  : null}}"
       aria-hidden="true">
     </i>
     <sub
       ui-grid-visible="isSortPriorityVisible()"
       class="ui-grid-sort-priority-number">
       {{col.sort.priority + 1}}
     </sub>
    </span>
  </div>

  <div
    role="button"
    tabindex="0"
    ui-grid-one-bind-id-grid="col.uid + '-menu-button'"
    class="ui-grid-column-menu-button"
    ng-if="grid.options.enableColumnMenus && !col.isRowHeader  && col.colDef.enableColumnMenu !== false"
    ng-click="toggleMenu($event)"
    ng-keydown="headerCellArrowKeyDown($event)"
    ui-grid-one-bind-aria-label="i18n.headerCell.aria.columnMenuButtonLabel"
    aria-haspopup="true">
    <i
      class="ui-grid-icon-angle-down"
      aria-hidden="true">
      &nbsp;
    </i>
  </div>

  <div ui-grid-filter></div>
</div>