【发布时间】:2021-10-25 05:30:07
【问题描述】:
数据表在正文加载后加载标题,对用户可见。第一个身体加载,并在几秒钟内标题正在扩展。在某些情况下,重新加载时页眉不会展开。
这是预加载的数据表。在这里使用延迟加载。
<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>
这就是我初始化数据表的方式。
$(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
});
})
这就是数据表在大多数情况下的显示方式,并且非常完美。
【问题讨论】:
-
一个minimal reproducible example 会很完美
标签: jquery datatable datatables