datatable不显示HTML表数据
dataTables not showing HTML table data
我有一个HTML表的数组,我在调用数据表之前构建,但我的表中的数据不显示,一旦我进行调用,除非我放置一个警报与代码一行数据表被调用之前。除非我删除'alert("Stop");'行,否则代码可以正常工作。下面是我的代码摘录:
// Code above builds HTML table contents
asHTML.push("</tr>");
asHTML.push("</table>");
$("#sandBox").html(asHTML.join('')); // Insert the lists into the DOM
$(document).ready(function() {
alert("Stop");
for(var i=0; i<data.SANDBOX.LIST.length; i++) {
$('#' + data.SANDBOX.LIST[i].LIST_ID).DataTable({
autoWidth: false,
"columnDefs": [
{ // Hide the 'Assigned' Column
"targets": [0],
"visible": false,
"orderable": false
},
{ // No sort on this column
"targets": [1],
"width": "1em",
"orderable": false
},
{ // No sort on this column
"targets": [2],
"orderable": false
},
{ // No sort on this column
"targets": [3],
"orderable": false
}
],
"paging": false,
"info": false,
"bFilter": false,
"scrollY": $("#parkingLot").height() - 50
});
}
尝试document load而不是ready
$(document.body).load(function() {
//alert("Stop");
....
完全删除ready
事件处理程序,不需要。
asHTML.push("</tr>");
asHTML.push("</table>");
$("#sandBox").html(asHTML.join('')); // Insert the lists into the DOM
for(var i=0; i<data.SANDBOX.LIST.length; i++) {
// ... skipped ...
}
问题已解决。它原来是由以下行引起的:
"scrollY": $("#parkingLot").height() - 50
$("#parkingLot").height()返回0。显然,那个元素还没有被渲染,尽管我认为"ready"函数应该已经调和了这一点。
"alert('Stop')"给页面时间来完全渲染元素,然后返回它的真实高度。
我认为你可以在DataTable的initComplete
事件中做scrollY
。您的元素将在此函数中呈现并可用。
$('#' + data.SANDBOX.LIST[i].LIST_ID).DataTable({
autoWidth: false,
"columnDefs": [
{ // Hide the 'Assigned' Column
"targets": [0],
"visible": false,
"orderable": false
},
{ // No sort on this column
"targets": [1],
"width": "1em",
"orderable": false
},
{ // No sort on this column
"targets": [2],
"orderable": false
},
{ // No sort on this column
"targets": [3],
"orderable": false
}
],
"paging": false,
"info": false,
"bFilter": false,
initComplete: function (settings, json) {
//do your stuff here, when everything is fully initialised and data loaded.
}
});
相关文章:
- 如何将json数据显示为html
- 使用html中的外部javascript进行数据验证
- 无法将数据从firebase获取到我的html页面
- JS验证ajax返回的html中的表单数据
- 将HTML表格导出到excel时,无法将数据加载到excel文件中
- 编辑HTML表的源数据
- PHP:显示sqlite数据库中的html格式数据,使用tinymce保存
- 在页面呈现之前更改HTML数据
- 如何放置'选择'基于angularJS中数据的html选项
- 有没有一种方法可以仅使用HTML/CSS来隐藏基于特定值的数据单元格
- AngularJS-需要在index.html页面中访问来自服务的数据
- AngularJS加载JSON数据,然后从中解析/加载HTML
- tu如何将id放在填充了json数据的html表td上
- 在HTML页面上显示node.js服务器中的数据
- 函数jquery.html()不提供数据属性集值
- 从远程站点获取数据 - HTML 表
- 如何保存和访问复选框数据 HTML
- 在下拉列表中显示保存的数据 - html 选择标签
- 避免使用jQuery显示的数据.html在页面重新加载后丢失
- 使用javascript根据元素的数据html将类附加到元素中