David Rinck
David Rinck

Reputation: 6996

Header-templates in UI-Grid 3.0

I would like to create two header rows with Angular UI-Grid 3.0. This is how it was done in ng-grid 2.0: http://plnkr.co/edit/i261iOpP2PdfGgg3C6ng?p=preview

With the newer grid, it appears to work at first, but if you click on any of the sorting columns the header size increases. Is there a work around for this? Or is my headerTemplate wrong?

$scope.gridOptions.headerTemplate = '<div class="ui-grid-header" >' + 
    '<div class="ui-grid-top-panel">' + '<div class="ui-grid-header-viewport">'
    +'<div class="ui-grid-header">' + 'Would like a grid header here' + '</div>'
    +'<div class="ui-grid-header-canvas" >' + '<div class="ui-grid-header-cell ui-grid-clearfix"  ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" ui-grid-header-cell col="col" render-index="$index" ng-style="$index === 0 && colContainer.columnStyle($index)">' + '</div></div></div></div></div>'

Complete code snippet with the faulty headerTemplate below:

var app = angular.module('app', ['ui.grid']);

app.controller('MainCtrl', ['$scope', '$log', function ($scope, $log) {


 $scope.gridOptions = {};

   $scope.gridOptions.columnDefs = [
         { name: 'firstName' },
         { name: 'lastName'},
         { name: 'Hyperlink',
             cellTemplate:'<div>' +
                       '  <a href="http://stackoverflow.com">Click me</a>' +
                       '</div>' }
       ];
    $scope.gridOptions.headerTemplate = '<div class="ui-grid-header" >' + 
        '<div class="ui-grid-top-panel">' + '<div class="ui-grid-header-viewport">'
        +'<div class="ui-grid-header">' + 'Would like a grid header here' + '</div>'
        +'<div class="ui-grid-header-canvas" >' + '<div class="ui-grid-header-cell ui-grid-clearfix"  ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" ui-grid-header-cell col="col" render-index="$index" ng-style="$index === 0 && colContainer.columnStyle($index)">' + '</div></div></div></div></div>'
 $scope.gridOptions.data = [
    {
        "firstName": "Cox",
        "lastName": "Carney",
        "company": "Enormo",
        "employed": true
    },
    {
        "firstName": "Lorraine",
        "lastName": "Wise",
        "company": "Comveyer",
        "employed": false
    },
    {
        "firstName": "Nancy",
        "lastName": "Waters",
        "company": "Fuelton",
        "employed": false
    }
];
}]);
<html ng-app="app">
  <head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <script src="http://ui-grid.info/release/ui-grid-unstable.js"></script>
    <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid-unstable.css" type="text/css">
    <link rel="stylesheet" href="main.css" type="text/css">
  </head>
  <body>

<div ng-controller="MainCtrl">
  <div ui-grid="gridOptions" class="grid"></div>
</div>


    <script src="app.js"></script>
  </body>
</html>

Upvotes: 0

Views: 5006

Answers (1)

mainguy
mainguy

Reputation: 8331

Most simple solution would be to add:

.ui-grid-header-cell {
    height: 30px !important;
}

to your css. This does not solve the mistery, but: Hey, it works! :-)

Look here: Plunker

Upvotes: 3

Related Questions