ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Custom headerCelltemplate

Open ashiquemohammed opened this issue 11 years ago • 12 comments

I am trying to built custom template for the cells of header of the grid. Referring [http://ui-grid.info/docs/#/api/ui.grid.class:GridOptions.columnDef] I tried to configure the columnDefs array . But that did not help . Please help .

ashiquemohammed avatar Jan 06 '15 10:01 ashiquemohammed

Try something like: http://plnkr.co/edit/JuDUwpUBwglkDRUYT77g?p=preview

The problem here is that the default headerCellTemplate is quite complex, and you need to copy all that in, then change the thing you want to change. There are some other options that you can use for formatting the header, including headerCellClass which lets you apply css styles such as fonts and colours, and headerCellFilter, which lets you transform the text in the header (useful for i18n for example). Perhaps one of those options would work better for you?

PaulL1 avatar Jan 07 '15 20:01 PaulL1

I'm sorry , But the plunker you provided is not working . I dont want to use headerCellClass or headerCellFilter , I wanted to change the template itself so that , the column name is not shown in the header and instead the input box has the column name as the placeholder text . Could I specify

headerCellTemaplate:"header-template.html"

within columnDefs.

Thank You

ashiquemohammed avatar Jan 09 '15 05:01 ashiquemohammed

That may work, I haven't tried. But you need to be careful with sorting, filter boxes and all the other things that appear in the header. It would also be fragile, as, given the amount of logic in the header template, there's a reasonable chance that it would be changed due to bug fixes or enhancements - you'd have to change your code whenever that happened.

If you just want the column name not show, you could define a filter that always returns "", that should work.

PaulL1 avatar Jan 09 '15 06:01 PaulL1

Dear Paul , But that is not working . I first tried to specify , headerCellTemplate:"header-template.html" which did not work . I then tried to paste the entire

angular.forEach(Object.keys($scope.gridData[0]), function (key) {
        def.push(
          {
            field: key,headerCellTemplate:'<div ng-class="{ \'sortable\': sortable }">'+
        '<div class="ui-grid-vertical-bar">&nbsp;</div>'+
        '<div class="ui-grid-cell-contents" col-index="renderIndex">'+
        //'<span>{{ col.displayName CUSTOM_FILTERS }}</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" class="ui-grid-column-menu-button" ng-click="toggleMenu($event)">'+
        '<i class="ui-grid-icon-angle-down">&nbsp;</i>'+
        '</div>'+
        '<div ng-if="filterable" class="ui-grid-filter-container" ng-repeat="colFilter in col.filters">'+
        //'<input type="text" class="ui-grid-filter-input" ng-model="colFilter.term" ng-attr-placeholder="{{colFilter.placeholder || ''}}" />
        '<div class="ui-grid-filter-button" ng-click="colFilter.term = null">'+
        '<i class="ui-grid-icon-cancel" ng-show="!!colFilter.term">&nbsp;</i>'+ <!-- use !! because angular interprets 'f' as false -->
        '</div>'+
        '</div>'+
        '</div>'
          }
        );

For both the case , the default template from the ui-grid/headerCell.html was being loaded . Why is that ?

ashiquemohammed avatar Jan 09 '15 06:01 ashiquemohammed

Try setting:

        headerCellFilter: function(value) {
          return "";
        }

I did it in a plunker, but plunker seems broken. But it does what you are looking for - blanking out the column header.

PaulL1 avatar Jan 09 '15 07:01 PaulL1

But that leaves a blank space above the input box . And what about specifying the placeholder for the input box .

ashiquemohammed avatar Jan 09 '15 07:01 ashiquemohammed

It was a mistake from my side . The columnDef I created was not being registered with the grid . For that reason it was automatically , building the header from the gridData and so with the default template . Thanks a lot for your time .

ashiquemohammed avatar Jan 09 '15 10:01 ashiquemohammed

Hi Paul,

I have this template as my custom header template

headerTemplate: '<div class="ui-grid-header custom-ui-grid-header"><div class="ui-grid-top-panel"><div class="ui-grid-header-viewport"><div class="ui-grid-header-canvas" style="width: 100%"><div class="ui-grid-header-cell-wrapper" style="display: block;" ng-style="colContainer.headerCellWrapperStyle()"><div class="ui-grid-header-cell-row" style="display: block; border-bottom: 1px solid;border-bottom-color: #d4d4d4;"><div class="ui-grid-header-cell" style="font-size:15px" ng-repeat="superCol in grid.options.superColDefs track by $index" col-name="{{superCol.name}}"><div class="ui-grid-cell-contents" data-ng-bind="superCol.displayName"></div><div class="info_icon_PP customTooltip_comp" style="margin-left:10px;margin-bottom:10px"><div class="tooltiptext_comp">{{grid.options.comp_tooltips[superCol.tooltipKey]}}</div></div></div></div><div class="ui-grid-header-cell-row"><div class="ui-grid-header-cell ui-grid-clearfix" ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" super-col-width-update ui-grid-header-cell col="col" render-index="$index"></div></div></div></div></div></div></div>',

I am unable to enable sorting on this template..Can u please guide me where am I wrong

soyiatgit avatar Nov 09 '16 08:11 soyiatgit

Hi All, Is there any way, i can edit the column name by clicking on the column header, like i can edit edit a cell in ui grid.

Thanks in advance, Aalokit

aalokits avatar Jul 24 '17 13:07 aalokits

@32teeths at least show your solution Y_Y I have the same problem with you Y_Y

ayami123 avatar Sep 12 '17 11:09 ayami123

@soyiatgit I am facing the same problem in my project.Did you get a workaround for this issue?

ChetnaGupta avatar Feb 13 '18 09:02 ChetnaGupta

@ChetnaGupta I believe it had something to do with a content class. Did u have a look here https://stackoverflow.com/questions/37279781/ui-grid-trigger-sorting-in-custom-header-template?rq=1

soyiatgit avatar Feb 13 '18 12:02 soyiatgit