我有一个简单的html表
<table id="mytable">
<thead>
<tr>
<th>Name</th>
<th colspan="2">Actions</th>
</tr>
<tr>
<th>Delete</th>
<th>Update</th>
</tr>
</thead>
<tbody>
<tr>
<td>MyName</td>
<td onclick="delete()">X</td>
<td onclick="update()">U</td>
</tr>
</tbody>
</table>
<script>
$(document).ready(function(){
$('#mytable').DataTable();
});
</script>
如果我在浏览器上打开它,我会得到
"Cannot read property 'mData' of undefined".
我不透露问题在哪里。我正在遵循官方示例:https://datatables.net/examples/basic_init/complex_header.html
谢谢大家!
您的HTML具有无与伦比的列数,请注意标题的第一行具有Colspan,而第二行没有。
您可以做的是提供一个rowspan。
<thead>
<tr>
<th rowspan="2">Name</th>
<th colspan="2">Actions</th>
</tr>
<tr>
<th>Delete</th>
<th>Update</th>
</tr>
</thead>
这是指向复杂标头的数据示例的链接。https://datatables.net/examples/basic_init/complex_header.html