我已经用django配置了数据表,当最多有6列时,它可以完美地工作。当我尝试再添加一列时,出现错误“未捕获的TypeError:无法读取未定义的属性'mData'”当我在chrome中检查时,获得错误显示的行(c.mData ===):如果(c.mData ===a){var d = w(b,“ sort”)|| w(b,“ order”),e = w(b,“ filter”)|| w(b,“ search”); if(d! == null || e!== null){c.mData = {_:a +“。display”,sort:d!== null?a +“。@ data-” + d:k,type:d!= = null?a +“。@ data-” + d:k,filter:e!== null?a +“。@ data-” + e:k}; ja(p,a)}}}}}}} var T = p.oFeatures,e = function(){if(g.aaSorting === k){var a = p.aaSorting; j = 0; for(i = a.length; j
由于动态渲染,我尝试提供静态数据以检查其是否仍然存在相同的问题。
这是我的html页面,
table.html
<div class="row mb-4">
<div class="col-12 mb-4">
<div class="card">
<div class="card-body">
<table class="data-table data-table-feature" id="dtable">
<thead>
<tr>
<th>Code</th>
<th>Description</th>
<th>Sort key</th>
<th>Is delete</th>
<th>Prefix</th>
<th>Edit</th>
<th>TEST</th>
</tr>
</thead>
<tbody>
{% for i in areas %}
<tr>
<td>{{ i.code }}</td>
<td>{{ i.description }}</td>
<td>{{ i.sort_key }}</td>
<td>{{ i.is_deleted }}</td>
<td>{{ i.prefix }}</td>
<td><a href="{% url 'edit-area-master' i.id %}">edit</a></td>
<td>TEST</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
我交叉检查了所有表格标签,请指出我错了。
我找到了解决方案,现在我可以添加任何一列。
test.html
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Position</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
{% for i in branches %}
<tr>
<td></td>
<td>{{ i.code }}</td>
<td>{{ i.description }}</td>
<td><a href="{% url 'edit-branch-master' i.id %}"
class="glyph-icon simple-icon-note"></a></td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
var t = $('#example').DataTable({
"columnDefs": [{
"searchable": false,
"orderable": false,
"targets": 0
}],
"order": [[1, 'asc']]
});
t.on('order.dt search.dt', function () {
t.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) {
cell.innerHTML = i + 1;
});
}).draw();
});
</script>