I tried a lot to freeze the header of a table in bootstrap but was not able to find any solution. I tried the code samples from the internet but the design of my table is getting messed up. My code follows below:
HTML
<div id="user_list" class="table-responsive">
<asp:GridView ID="grdUsersList" runat="server" AutoGenerateColumns="false" CssClass="table table-hover" HeaderStyle-CssClass="info" BorderWidth="0px" GridLines="Horizontal" Width="100%">
</asp:GridView>
</div>
CSS for above div
#user_list {
overflow:auto;
border: 1px solid #337AB7;
max-height: 500px;
}
#user_list table {
border-color: #337AB7;
}
#user_list table th {
font-weight: bold;
}
Now, finally populating grid dynamically using jquery
$('#ChildContent_grdUsersList').append('<thead></thead>');
$('#ChildContent_grdUsersList thead').append('<tr><th class="info" style="width: 3%;"></th>\
<th class="info" style="width: 12%;">Name</th>\
<th class="info" style="width: 15%;">Login ID</th>\
<th class="info" style="width: 15%;">Email ID</th>\
<th class="info" style="width: 10%;">Phone No.</th>\
<th class="info" style="width: 13%;">Designation</th>\
<th class="info" style="width: 12%;">Reporting To</th>\
<th class="info" style="width: 10%;">Business</th>\
<th class="info" style="width: 10%;">User Type</th></tr>');
$.each(response, function (index, itemData) {
$('#ChildContent_grdUsersList').append('<tr><td class="text-left"><input type="radio" id="radio_' + itemData.UserID + '" name="user" class="radio" value="' + itemData.UserID + '" onchange="showVal(this);"></input></td>\
<td class="text-left">' + itemData.UserName + '</td>\
<td class="text-left">' + itemData.LoginId + '</td>\
<td class="text-left">' + itemData.EmailId + '</td>\
<td class="text-left">' + itemData.Phone + '</td>\
<td class="text-left">' + itemData.Designation + '</td>\
<td class="text-left">' + itemData.ReportingTo + '</td>\
<td class="text-left">' + itemData.BusinessAssigned + '</td>\
<td class="text-left">' + itemData.UserType + '</td></tr>');
});
I want to freeze the header of the above table. On applying display:block;
to <thead>
and <tbody>
, the whole design is getting messed up.
I even tried applying "sticky headers", "freeze headers" kind of plugins but still the headers are not getting fixed.
Please help me.
Thanks.