由于@yuwang说,这是数据表是如何工作的。我们自己也对此感到困惑 - 问题在于DataTable在初始化方面速度非常慢,大约4000条记录似乎成为大多数浏览器的障碍。在我们的应用程序中,我只设置了4000个限制 - DataTables视图主要是为了方便,人们可以进行更窄范围的搜索。 Serverside处理不是真正的解决方案。
关于“负荷只有少数记录的第一页 - 在同一时间,做页面加载背景Ajax调用兴建第二座全表”,试试这个:
服务器。 PHP,与brief=yes
调用如果只有前100条记录应加载
<table id="test-table">
<thead>
<th>id</th>
<th>date</th>
<th>text</th>
</thead>
<tbody>
<?
function getColumn() {
$row='<tr>';
$row.='<td>'.rand(1, 100000).'</td>';
$row.='<td>'.date("Y-m-d H:i:s", mt_rand(1232055681, 1762855681)).'</td>';
$row.='<td>'.str_shuffle('abcdefghijklmnopqr').'</td>';
$row.='</tr>';
return $row;
}
$count=(isset($_GET['brief'])) ? 100 : 10000;
for ($i=0;$i<$count;$i++) {
echo getColumn();
}
?>
</tbody>
</table>
完全正常的例子(复制和粘贴)
<!DOCTYPE html>
<html lang="en">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
$.ajax({
url: 'server.php?brief=yes',
success : function(html) {
$('#table-container').html(html);
$("#test-table").DataTable();
$.ajax({
url: 'server.php',
success : function(html) {
$('#table-container').html(html);
$("#test-table").DataTable();
}
});
}
});
});
</script>
</head>
<body>
<div id="table-container"></div>
</body>
</html>
关当然,在server.php的记录总是变化的内容,当你从数据库加载记录(或其他)
恐怕数据表不出货,这将不会是这样与您请求的功能。根据我的经验,当数据集很大(3000+)时,页面加载会非常缓慢。你可以尝试[服务器端处理](http://datatables.net/release-datatables/examples/data_sources/server_side.html),它可以很好地调节性能。 – yuwang 2013-05-23 18:09:42