Javascript 无法解析Datatable SCRIPT5007:无法设置属性'_DT#U CellIndex';指未定义的或空的引用
我无法解决以下Datatables错误: SCRIPT5007:无法设置未定义或 空引用 我试着在互联网上搜索,发现这是最好的解决方案。但我仍然无法解决这个问题。我是不是遗漏了什么?我是JavaScript的新手。在这里找到了这个答案: 一个简单的错误是,表格标题有一列“没有” 标题,但该列在表本身中不存在。我无法 看到它丢失了(因为没有标题和边框)Javascript 无法解析Datatable SCRIPT5007:无法设置属性'_DT#U CellIndex';指未定义的或空的引用,javascript,jquery,datatables,Javascript,Jquery,Datatables,我无法解决以下Datatables错误: SCRIPT5007:无法设置未定义或 空引用 我试着在互联网上搜索,发现这是最好的解决方案。但我仍然无法解决这个问题。我是不是遗漏了什么?我是JavaScript的新手。在这里找到了这个答案: 一个简单的错误是,表格标题有一列“没有” 标题,但该列在表本身中不存在。我无法 看到它丢失了(因为没有标题和边框) 它起作用了吗?我们也有同样的错误!我们解决这个问题的方法是根据从0开始的列数更改数据表中的目标 在我们的表中有4列,因此目标:[3] $.exte
它起作用了吗?我们也有同样的错误!我们解决这个问题的方法是根据从0开始的列数更改
数据表中的目标
在我们的表中有4列,因此目标:[3]
$.extend($.fn.dataTable.defaults,{
columnDefs: [{
targets: [3]
}]
});
基本上,这个问题的出现是因为th到td的匹配计数不匹配。请确保th到td的匹配数。希望这对您有所帮助。检查表列的计数和dtColumnDefs
如果您有6列,那么下面将是您对dtColumnDefs
的配置
self.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0),
DTColumnDefBuilder.newColumnDef(1),
DTColumnDefBuilder.newColumnDef(2),
DTColumnDefBuilder.newColumnDef(3),
DTColumnDefBuilder.newColumnDef(4),
DTColumnDefBuilder.newColumnDef(5)
];
我修复了它。它是js部分vshtml
当我删除html列,忘记删除一个类似这样的js列时,出现了问题
{"name": "Product", "orderable": true, "searchable": true},
一旦我删除了js中的额外列,一切都开始工作。要解决此错误:
无法设置未定义的属性“\u DT\u CellIndex”
首先,我告诉您,$(“id\u tu\u tabla”).Datatable()的列数最少,为6。但是如果列数少于6,则必须指定它,如以下代码所示:
$('#table').DataTable({ columnDefs: [ { goals: [4] }] }); }
似乎很多人都是因为th和td不匹配而出错的。对我来说,我的错误似乎是逻辑错误。请看下面的代码
注意:这是我在Angular 7中对数据表进行的实验,增强了*ngFor、ng container、*ngIf之类的功能,但没关系,只要看看代码结构的差异(用ng container
替换tr
)
桌头:
<thead>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Email</th>
<th>Organisation</th>
</tr>
</thead>
名称
姓
电子邮件
组织
这将产生以下错误:
<tr *ngFor="let user of users; let index = index">
<ng-container *ngIf="showInactiveUsers">
<td>{{user?.firstName}}</td>
<td>{{user?.lastName}}</td>
<td>{{user?.email}}</td>
<td>{{user?.attributes?.organisation}}</td>
</ng-container>
<ng-container *ngIf="!showInactiveUsers && user?.enabled">
<td>{{user?.firstName}}</td>
<td>{{user?.lastName}}</td>
<td>{{user?.email}}</td>
<td>{{user?.attributes?.organisation}}</td>
</ng-container>
</tr>
<ng-container *ngFor="let user of users; let index = index">
<tr *ngIf="showInactiveUsers">
<td>{{user?.firstName}}</td>
<td>{{user?.lastName}}</td>
<td>{{user?.email}}</td>
<td>{{user?.attributes?.organisation}}</td>
</tr>
<tr *ngIf="!showInactiveUsers && user?.enabled">
<td>{{user?.firstName}}</td>
<td>{{user?.lastName}}</td>
<td>{{user?.email}}</td>
<td>{{user?.attributes?.organisation}}</td>
<td *ngIf="user?.enabled">
</tr>
</ng-container>
{{user?.firstName}
{{user?.lastName}
{{用户?.email}
{{用户?.attributes?.organization}
{{user?.firstName}
{{user?.lastName}
{{用户?.email}
{{用户?.attributes?.organization}
按如下方式重新排列代码可解决此错误:
<tr *ngFor="let user of users; let index = index">
<ng-container *ngIf="showInactiveUsers">
<td>{{user?.firstName}}</td>
<td>{{user?.lastName}}</td>
<td>{{user?.email}}</td>
<td>{{user?.attributes?.organisation}}</td>
</ng-container>
<ng-container *ngIf="!showInactiveUsers && user?.enabled">
<td>{{user?.firstName}}</td>
<td>{{user?.lastName}}</td>
<td>{{user?.email}}</td>
<td>{{user?.attributes?.organisation}}</td>
</ng-container>
</tr>
<ng-container *ngFor="let user of users; let index = index">
<tr *ngIf="showInactiveUsers">
<td>{{user?.firstName}}</td>
<td>{{user?.lastName}}</td>
<td>{{user?.email}}</td>
<td>{{user?.attributes?.organisation}}</td>
</tr>
<tr *ngIf="!showInactiveUsers && user?.enabled">
<td>{{user?.firstName}}</td>
<td>{{user?.lastName}}</td>
<td>{{user?.email}}</td>
<td>{{user?.attributes?.organisation}}</td>
<td *ngIf="user?.enabled">
</tr>
</ng-container>
{{user?.firstName}
{{user?.lastName}
{{用户?.email}
{{用户?.attributes?.organization}
{{user?.firstName}
{{user?.lastName}
{{用户?.email}
{{用户?.attributes?.organization}
如果您要求显示带有“未找到记录”消息的行,如下面的代码
@if(Model.Count==0)
{
<tr>
<td colspan="3">
No record found.
</td>
</tr>
}
@if(Model.Count==0)
{
没有找到任何记录。
}
然后简单地删除这个条件,因为datatable本身附加了“表中没有可用的数据”“消息,在我的情况下,它是解决我的错误我有一个类似的问题,它是通过删除列名中的“$”符号修复的。希望这有帮助。在我的例子中,在一行中使用colspan时,单元格的数量与表头不匹配,因此显示此错误。您可以添加这些隐藏的单元格以消除该错误
试试这个
<tr>
<td colspan="4">details</td>
<td style="display: none"></td>
<td style="display: none"></td>
<td style="display: none"></td>
</tr>
细节
添加所需的单元格,但隐藏它们当数据表中没有数据时,我出现了错误。桌子是空的。添加一条记录后,错误消失。我也遇到了同样的问题。在我的例子中,我有5列,但在可订购目标中,我设置了7列。因此,请确保在可订购目标中也没有提到额外的列
{ "orderable": false, "targets": [1,2,3,4] }
它似乎不起作用…..你知道我如何检查我的table thead tag td是否与我的table tbody td匹配吗?Hi@a7madgamal让我在jsbin上上传代码,但是。。下面是IE 11被卡住的代码:-for(i=0,iLen=oSettings.aoColumns.length;我基本上就是这样。添加的列数应该与初始化的列数相同。为我保存了我的时间,我使用ajax在表上加载数据,但调用函数$('#TableID')。DataTable()
在将任何数据加载到表中之前,因此存在此问题。因此,我需要在success:function()中调用此函数
加载表数据后的ajax调用。以下是解决此问题的方法,对于meHello来说,没有详细信息的回答并没有真正的帮助。您可以添加更多详细信息吗?为什么这会解决此问题?在我的例子中,使用colspan在一行中,单元格的数量与表头不匹配,因此显示此错误。您可以将这些隐藏的单元格添加到ge请编辑您的答案:)