[英]Jquery datatable functionality not apply after render the datatable in <f:ajax>
[英]jQuery datatable functionality inoperable
我已经和Datatables合作了一段时间,但显然,我并没有以正确的方式使用它们。
在过去,我将使用$ .post启动我的数据表,如下所示:
$(document).ready(function() {
$.post('process/recordTables.php', function(data)
{
var table = $('#example1').DataTables();
table.clear();
var obj = JSON.parse(data);
obj.forEach(function(item)
{
table.row.add([item.column1, item.column2, //and so on]);
});
table.draw();
});
});
上面的代码有效。 我的数据表打印出我需要的数据。 在obj.forEach中,如果需要,我可以使用href标记和其他功能设置列。
但是,如果我想能够在设定的时间间隔内重新加载数据表,我就不能使用上述方法。 它必须使用“ajax”方法。
经过一些试验和错误,使用下面的代码,我能够打印出jQuery Datatables的“正确”形式(和使用):
$(document).ready(function()
{
$('#example1').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "process/recordTables.php", // same url as the above code
"type": "POST",
"dataSrc": ''
},
"columns": [
{ "data": "" },
{ "data": "column1" },
{ "data": "column2" },
{ "data": "column3" },
// and so on
],
"iDisplayLength": 25,
"order": [[ 3, "desc" ]],
"scrollY": 550,
"scrollX": true,
"bDestroy": true,
"stateSave": true,
// few others that don't seem to affect functionality
});
});
使用上面的代码,我能够使用$ .post方法显示相同的数据。
但是......没有任何功能可行。 排序不起作用。 分页,搜索过滤器,表格底部的数据信息显示“0个条目中的0个”。 什么都行不通。
我错过了哪些可以解决这个问题? 我很困惑。
这是HTML表:
<table id="example1" class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th></th>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
// and so on
</tr>
</thead>
<tbody>
</tbody>
</table>
当您添加"serverSide": true
,attribute时,您将DataTable
设置为服务器端处理 。 在这种情况下,禁用所有客户端处理:
启用服务器端处理后,DataTable执行的所有分页,搜索和排序操作都将传递给服务器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.