[英]DataTables using JavaScript data source
I am trying to implement a simple dataTables example using JavaScript object as a data source following the template here (second example). 我试图在此处的模板后面使用JavaScript对象作为数据源来实现一个简单的dataTables示例(第二个示例)。 Please see code below:
请参见下面的代码:
$("#dynamicScenarioTblContainer div:last table").DataTable({ //initialize table with extras
"data" : [{"NoData": "no data"}],
"columns": [{ "data" : "NoData" }]
});
Although the code seems to follow the same logic as the example I am getting 尽管代码似乎遵循与示例相同的逻辑
'Uncaught TypeError: Cannot read property 'length' of undefined'
'未捕获的TypeError:无法读取未定义的属性'length'
Update: 更新:
var DSDefaultSettings = '<table class="display compact" cellspacing="0" width="100%"><tr><thead></thead></tr><tbody></tbody>/table>';
$("#dynamicScenarioTblContainer").append("<div></div>")
$("#dynamicScenarioTblContainer div:last").html(DSDefaultSettings);
$("#dynamicScenarioTblContainer div:last table").DataTable({ //initialize table with extras
"data": [{"NoData": "no data"}],
"columns": [{ "data": "NoData" }]
});
There is no tbody
element in your table and the thead
should not be encapsulated by a tr
. 您的表中没有
tbody
元素,并且thead
不应由tr
封装。
Reference: http://www.w3schools.com/tags/tag_thead.asp 参考: http : //www.w3schools.com/tags/tag_thead.asp
The correct HTML for the table should be: 该表的正确HTML应该是:
var DSDefaultSettings = '<table class="display compact" cellspacing="0" width="100%"><thead></thead><tbody></tbody></table>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.