7

I want to add some custom field in columnDefs and want to access it from header template. As an example , i want a field let say showFile

$scope.gridOptions.columnDefs = [
       {                
                name: 'ServiceID',
                displayName: 'Service',
                showFile: some data
      }]

and want to access showFile inside header template ...

<div class="ui-grid-top-panel"  style="text-align: center">
      {{ want to access 'showFile' }}
</div>

What's the best possible way to do this. As i have tried it using custom method as

<div class="ui-grid-top-panel"  style="text-align: center">
{{grid.appScope.letter()}}
</div>

(plnkr link http://plnkr.co/edit/ZW43LsiLY7GdnX6XEOgG?p=preview , http://plnkr.co/edit/3E8HTz4Z2daGqRh1WHtx?p=preview) but , the function (grid.appScope.letter()) is being called for infinite number of times . I have raised the issue but didn't got any reply .. https://github.com/angular-ui/ui-grid/issues/4250 , https://github.com/angular-ui/ui-grid/issues/4314. Can anyone please suggest the best possible way to achieve the above mentioned task.

3 Answers 3

1

Try using renderIndex. This will give you the column's index.

{{grid.appScope.gridOptions.columnDefs[renderIndex].customField}}
Sign up to request clarification or add additional context in comments.

Comments

0

To access showFile in there, have you tried...

{{grid.appScope.gridOptions.columnDefs[0].showFile}}

Comments

0

I edited the plnkr: http://plnkr.co/edit/kdU59pZYQT0B76vYBQC8?p=preview.

I'm not sure if that's what you want to do, i used the headerCellTemplate in the columnDefs object instead of the headerTemplate, then you access with: {{col.colDef.showFile}}

columnDefs: [{
    field: 'name',
    displayName: 'First Name',
    width: 90
  }, {
    field: 'title',
    displayName: 'Last Name',
    width: 80
  }, {
    field: 'test',
    displayName: 'test',
    width: 80,
    showFile: 'FILE',
    headerCellTemplate: '<div ng-class="{ \'sortable\': sortable }">' +
      '<div class="ui-grid-cell-contents" col-index="renderIndex" title="TOOLTIP">' +
      '<span>{{ col.displayName CUSTOM_FILTERS }}</span><br /><span>{{col.colDef.showFile}}</span>' +
      '<span ui-grid-visible="col.sort.direction" 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 }">' +
      '&nbsp;' +
      '</span>' +
      '</div>' +
      '<div class="ui-grid-column-menu-button" ng-if="grid.options.enableColumnMenus && !col.isRowHeader  && col.colDef.enableColumnMenu !== false" ng-click="toggleMenu($event)" ng-class="{\'ui-grid-column-menu-button-last-col\': isLastCol}">' +
      '<i class="ui-grid-icon-angle-down">&nbsp;</i>' +
      '</div>' +
      '<div ui-grid-filter></div>' +
      '</div>'
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.