You can do it easily with puse CSS without any kind of JS. you have to add position: sticky; top: 0; z-index:999;
in table th
. But this won't work on Chrome Browser but other browser. To work on chrome you have to add those code in table thead th
.table-fixed {_x000D_
width: 100%;_x000D_
}_x000D_
_x000D_
/*This will work on every browser but Chrome Browser*/_x000D_
.table-fixed thead {_x000D_
position: sticky;_x000D_
position: -webkit-sticky;_x000D_
top: 0;_x000D_
z-index: 999;_x000D_
background-color: #000;_x000D_
color: #fff;_x000D_
}_x000D_
_x000D_
/*This will work on every browser*/_x000D_
.table-fixed thead th {_x000D_
position: sticky;_x000D_
position: -webkit-sticky;_x000D_
top: 0;_x000D_
z-index: 999;_x000D_
background-color: #000;_x000D_
color: #fff;_x000D_
}
_x000D_
<table class="table-fixed">_x000D_
<thead>_x000D_
<tr>_x000D_
<th>Table Header 1</th>_x000D_
<th>Table Header 2</th>_x000D_
<th>Table Header 3</th>_x000D_
</tr>_x000D_
</thead>_x000D_
<tbody>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
<td>Data</td>_x000D_
</tr>_x000D_
</tbody>_x000D_
</table>
_x000D_