I've been trying to make the header stay fixed. No matter that when scroll down to show the other data, always the <th>
are posted visible. I tried to do it by following this post but by adding position: block
in the styles for <th>
and <td>
, the th change from this to this
losing consistency th with their respective td and it stops me accepting the
colspan
, it stops me from showing the <th>
below the respective <td>
.
How could I make the header always visible without losing the table design?
.td2 {
padding: 5px 7px !important;
text-align: center !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="scroll-table-container" style="height: 300px">
<table id="myTableLP" class="table scroll-table table-striped table-bordered table-condensed table-hover">
<thead>
<tr>
<th class="component_name_header_col th" colspan="2">Descripción</th>
<th class="component_name_header_col th" colspan="2">Inventario Inicial</th>
<th class="component_name_header_col th" colspan="2">Ventas</th>
<th class="component_name_header_col th" colspan="2">Entregas</th>
<th class="component_name_header_col th" colspan="2">Devoluciones</th>
<th class="component_name_header_col th" colspan="2">Merma</th>
<th class="component_name_header_col th" colspan="2">Promoción</th>
<th class="component_name_header_col th" colspan="2">Obsequio</th>
<th class="component_name_header_col th" colspan="2">Recarga</th>
<th class="component_name_header_col th" colspan="2">Inventario Sobrante</th>
<th class="component_name_header_col th" colspan="2">Descarga</th>
<th class="component_name_header_col th" colspan="2">Pedido Día Siguiente</th>
<th class="component_name_header_col th" colspan="2">Inventario Total</th>
</tr>
<tr>
<th>SKU
<input type="text" id="LP" onkeyup="myFunctionLP(variable='LP',columna=0)" placeholder="">
</th>
<th>Producto
<input type="text" id="LP2" onkeyup="myFunctionLP(variable='LP2',columna=1)" placeholder="">
</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
<th>Cajas</th>
<th>Piezas</th>
</tr>
</thead>
<tbody>
<tr>
<td>
2010101
</td>
<td>
Product
</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
<td class="td2">15</td>
</tr>
</tbody>
</table>
</div>