Data tables loads header after the body loads, its visible to user. First body loads and in few seconds header is expanding. In some cases when reload the page headers are not expanding.
This is the preloaded data table. Using defer loading here.
<div id="dataTableWrapper" style="display:none;">
<table id="result" width="100%" class="table cell-border" cellspacing="0" cellpadding="0" border="0" >
<thead>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</thead>
<tbody id="searchResultsDiv">
<c:forEach items="${list}" var="info" varStatus="tIndex">
<tr>
<td >${tIndex.index + 1}</td>
<td >${info.typeDesc}</td>
<td >${info.time}-</td>
<td >${info.id}</td>
<td >${info.number}</td>
<td >${info.name}</td>
<td >${info.description}</td>
<td >${info.boDescription}</td>
<td >${info.userId}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
This is how I intialize the data table.
$(document).ready(function() {
$('#result').DataTable({
serverSide: true,
processing: false,
searching: false,
lengthChange: false,
loading: false,
deferLoading: $("#totalRecordsCount").val(),
order: [
[1, "desc"]
],
ajax: {
type: "POST",
contentType: "application/x-www-form-urlencoded; charset=windows-1256",
url: $("#context").val() + "/Controller?actionParam=getResultForPagination",
data: buildSearchData,
dataSrc: function(json) {
return json.data;
}
},
//stateSave:false,
scrollY: "735px",
scrollCollapse: true,
fixedHeader: true,
paging: true,
pageLength: $("#pageSize").val(),
initComplete: function() {
var api = this.api();
$('#dataTableWrapper').show();
api.columns.adjust();
},
//single page? do not display pagination
fnDrawCallback: function(oSettings) {
if (oSettings._iDisplayLength > oSettings.fnRecordsDisplay()) {
$(oSettings.nTableWrapper).find('.dataTables_paginate').hide();
$(oSettings.nTableWrapper).find('.dataTables_info').hide();
} else {
$(oSettings.nTableWrapper).find('.dataTables_paginate').show();
$(oSettings.nTableWrapper).find('.dataTables_info').show();
}
},
//processing :true,
language: dataTable_lang_values
});
})
This is how the data table appears most of the times and its perfect.
But on sometimes when we keep reloading the page it appears like this.