gpt4 book ai didi

jquery - 将 DataTable 与 colspan 一起使用时,无法读取未定义的属性 'mData'

转载 作者:行者123 更新时间:2023-12-01 06:26:11 24 4
gpt4 key购买 nike

我正在使用数据表来显示来自服务器的数据。问题是我在控制台中不断收到错误消息:

datatables.min.js:145 Uncaught TypeError: 无法读取未定义的属性“mData”

我几乎访问了互联网上与此相关的每个链接,但没有任何对我有用。

我已使用 colspans 确保 thead 和 tbody 中的列数相同。

我可能遗漏了一些东西,但在花了相当长的时间之后,我希望在这里得到一些帮助。

代码如下

HTML:

<table id="data-table" class="display table" width="100%">
<thead>
<tr>
<th colspan="4" class="center-align solid-left-border" style="border-bottom: none; text-decoration: underline; text-transform: uppercase; padding: 5px 18px;">
Tier 2 Contributions Report
</th>
</tr>

<tr>
<th class="left-align solid-left-border" style="border-bottom: none; text-decoration: none; text-transform: uppercase; font-weight: normal; font-weight: normal; padding: 5px 18px; font-size: 12.5px">
Employer's FIle No/Registration No:
</th>

<th colspan="3" class="left-align solid-left-border" style="border-bottom: none; font-weight: normal; padding: 5px 18px; font-size: 12.5px; text-transform: uppercase;">
<%= company.getSSNITRegistration() || '-' %>
</th>
</tr>

<tr>
<th class="left-align solid-left-border" style="border-bottom: none; text-decoration: none; text-transform: uppercase; font-weight: normal; padding: 5px 18px; font-size: 12.5px;">
Name of Employer:
</th>

<th colspan="3" class="left-align solid-left-border" style="border-bottom: none; font-weight: normal; padding: 5px 18px; font-size: 12.5px; text-transform: uppercase;">
<%= company.getName() || '-' %>
</th>
</tr>

<tr>
<th class="left-align solid-left-border" style="border-bottom: none; text-decoration: none; text-transform: uppercase; font-weight: normal; padding: 5px 18px; font-size: 12.5px;">
Address of Employer:
</th>

<th colspan="3" class="left-align solid-left-border" style="border-bottom: none; font-weight: normal; padding: 5px 18px; font-size: 12.5px; text-transform: uppercase;">
<%= company.getAddress() || '-' %>
</th>
</tr>


<tr>
<th colspan="4" style="border-bottom: none;"></th>
</tr>
</thead>

<tfoot>
<tr>
<th colspan="2" class="left-align">Totals</th>
<th class="center-align"><%= addCommas(totals.basicSalary) %></th>
<th class="right-align"><%= addCommas(totals.contribution) %></th>
</tr>
</tfoot>

<tbody>
<tr>
<th class="left-align">Social Sec. No.</th>
<th class="left-align">Full Name</th>
<th class="center-align">Basic Salary</th>
<th class="right-align">Contribution (5%)</th>
</tr>

<% employees.forEach(function(employee) { %>
<tr>
<td class="left-align"><%= employee.ssnitNumber %></td>
<td class="left-align"><%= employee.lastName + ', ' + employee.firstName + ' ' + employee.otherNames%></td>
<td class="center-align"><%= addCommas(employee.basicSalary) %></td>
<td class="right-align"><%= addCommas(employee.contribution) %></td>
</tr>
<% }) %>
</tbody>
</table>

JS

$('#data-table').DataTable( {
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"bSort": false,
"bInfo": true,
"bAutoWidth": false,
"dom": 'Bfrtip',
"buttons": [
'copy', 'csv', 'excel', 'pdf', 'print'
]

});

最佳答案

此类问题的一般原因是

  1. 标题列和页脚列不匹配。

  2. Body 元素与 header 不匹配(一行中的 td 数量应与 header 中的 <th> 匹配)。

  3. 表 ID 重复。

在您的情况下,请从 <tbody> 移动标题(如社交账号等)至<thead> ,并且您的页眉和页脚不匹配,请使它们相同,因为我看到页眉中有 4 个元素,页脚中只有 3 个元素。

关于jquery - 将 DataTable 与 colspan 一起使用时,无法读取未定义的属性 'mData',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36684959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com