[英]Getting this error - Unable to get property 'mData' of undefined or null reference
I am getting the below error when I use the jQuery data table. 当我使用jQuery数据表时,我收到以下错误。
Error: Unable to get property 'mData' of undefined or null reference 错误:无法获取未定义或空引用的属性“mData”
Code 码
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#empTable').DataTable();
} );
</script>
<table id="empTable" class="display" width="100%">
<tr>
<th>Name</th>
<th>Age</th>
<th>Address</th>
</tr>
<tr>
<td>AAAAA</td>
<td>32</td>
<td>Colombo</td>
</tr>
<tr>
<td>BBBBB</td>
<td>29</td>
<td>Kandy</td>
</tr>
</table>
Please suggest me how to fix this issue? 请建议我如何解决这个问题?
Your html structure is not proper, you need to have a thead
element where the header is specified and the content should be in tbody
. 你的html结构不正确,你需要有一个指定标题的
thead
元素,内容应该是tbody
。
$(document).ready(function() { $('#empTable').DataTable(); });
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.js"></script> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/css/jquery.dataTables.css" /> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/js/jquery.dataTables.js"></script> <table id="empTable" class="display" width="100%"> <thead> <tr> <th>Name</th> <th>Age</th> <th>Address</th> </tr> </thead> <tbody> <tr> <td>K.Senthuran</td> <td>32</td> <td>42nd Lane</td> </tr> <tr> <td>S.Senthuran</td> <td>29</td> <td>Hampden Lane</td> </tr> </tbody> </table>
$(document).ready(function() { $('#empTable').DataTable(); });
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.js"></script> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/css/jquery.dataTables.css" /> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/js/jquery.dataTables.js"></script> <table id="empTable" class="display" width="100%"> <thead> <tr> <th>Name</th> <th>Age</th> <th>Address</th> </tr> </thead> <tbody> <tr> <td>K.Senthuran</td> <td>32</td> <td>42nd Lane</td> </tr> <tr> <td>S.Senthuran</td> <td>29</td> <td>Hampden Lane</td> </tr> </tbody> </table>
HTML structures in the table needs to match. 表中的HTML结构需要匹配。 For instance,
<th>
tags in your <thead>
with the <tr>
's in the <tbody>
. 例如,
<th>
<thead>
<th>
标记与<tbody>
的<tr>
<tbody>
。 That is, if in the table you expect 5 columns , there should be 5 <th>
tags in the table head and 5 <tr>
tags in the table body. 也就是说,如果在表中你期望有5列,那么表头中应该有5
<th>
标签,表体中应该有5 <th>
<tr>
标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.