The first option is to split table header and table body in two tables. One way to do this is to follow the next steps:
.div-table-body { height: 600px; overflow-x: auto; overflow-y: scroll; }
th
elements have the same padding as td
elements have.padding-right
with the value of scroll bar width to make an offset for the table contains header.width
attribute for columns to sync widths.Code Sample:
<table> <thead> ... </thead> </table> <table> <tbody class="div-table-body"> ... </tbody> </table>
Another option is to use the directive fixed-header
that can be injected to the Data Grid like a separate module dataGridUtils
.
To make it work it is needed to perform next steps:
<script src="bower_components/angular-data-grid/dist/dataGridUtils.min.js"></script>
<link rel="stylesheet" href="bower_components/angular-data-grid/css/fixedHeader/fixed-header.css">
angular.module('myApp', ['dataGrid', 'dataGridUtils.fixedHeader'])
fixed-header
to the grid table: <table class="table" fixed-header>
The directive uses z-index: 99
if your page uses the same value or higher please make appropriate changes to fixed-header.scss file.
The directive also has additional attribute offset-from-element
.
It is needed if you already have some other elements with fixed position above the table.
In this case you need to pass a class or id of the very last element (if there are several) to this attribute
to make the directive take
into consideration that header needs to be fixed with offset from above elements.
Example:
<table class="table" fixed-header offset-from-element=".the-class-on-above-fixed-element">or
<table class="table" fixed-header offset-from-element="#the-id-on-above-fixed-element">
Order # | Date Placed | Total | |
---|---|---|---|
See the Pen xZddZm by AngularDataGrid (@AngularDataGrid) on CodePen.