Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-grid headerRowTemplate - Has anyone used this?

My team are wanting to use this feature of ng-grid. However it does not seem to be documented anywhere. What we would like to do is to put a "plus" icon into the last column of the header area of a ng-grid.

Has anyone found a good way to do this?

like image 942
Alan2 Avatar asked Apr 20 '13 09:04

Alan2


1 Answers

Just modify the headerCellTemplate for the last column in your grid (see https://github.com/angular-ui/ng-grid/wiki/Templating).

Here is an example (note <img src="PLUS-ICON.png" /> in the second line):

var myHeaderCellTemplate = '<div class="ngHeaderSortColumn {{col.headerClass}}" ng-style="{\'cursor\': col.cursor}" ng-class="{ \'ngSorted\': !noSortVisible }">' +
                           '<div ng-click="col.sort($event)" ng-class="\'colt\' + col.index" class="ngHeaderText">{{col.displayName}} <img src="PLUS-ICON.png" /></div>' +
                           '<div class="ngSortButtonDown" ng-show="col.showSortButtonDown()"></div>' +
                           '<div class="ngSortButtonUp" ng-show="col.showSortButtonUp()"></div>' +
                           '<div class="ngSortPriority">{{col.sortPriority}}</div>' +
                           '<div ng-class="{ ngPinnedIcon: col.pinned, ngUnPinnedIcon: !col.pinned }" ng-click="togglePin(col)" ng-show="col.pinnable"></div>' +
                           '</div>' +
                           '<div ng-show="col.resizable" class="ngHeaderGrip" ng-click="col.gripClick($event)" ng-mousedown="col.gripOnMouseDown($event)"></div>';
$scope.gridOptions = {
    data: self.myData,
    columnDefs: [
        { field: 'firstField', displayName: 'First Column' },
        { field: 'secondField', displayName: 'Second Column' },
          ...
        { field: 'lastField', displayName: 'Last Column', headerCellTemplate: myHeaderCellTemplate }
    ]
};
like image 180
Kabb5 Avatar answered Jan 02 '23 12:01

Kabb5