Angular-UI grid : adding custom field in columnDefs and access it from header template
Asked Answered
B

3

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.

Branks answered 22/9, 2015 at 16:42 Comment(0)
D
1

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

{{grid.appScope.gridOptions.columnDefs[renderIndex].customField}}
Deepsea answered 1/10, 2015 at 10:27 Comment(0)
D
0

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

{{grid.appScope.gridOptions.columnDefs[0].showFile}}
Dialogize answered 24/9, 2015 at 22:19 Comment(0)
L
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>'
  }
Loader answered 24/9, 2015 at 22:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.