Djangoでデータテーブルを作成すると、ハードコードされたときに正常に機能しますが、Djangoテンプレートタグを追加すると破損します。ページの検査では、Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined
のjquery.datatables.min.jsにあります。Djangoで行を追加するとデータテーブルが破損する
これは、私がテーブルに複数のユーザーがいる場合、またはdjangoでテーブルに列を追加しようとした場合にのみ発生します。私は自分のプロジェクトで複数のデータセットを使用するので、私が間違っていることを理解する必要があります。私が使用しているdatatable JSコードはテンプレートから来ており、エラーがテンプレートコードまたは私のDjangoテンプレートコードにあるかどうかはわかりません。だから、長いコードブロックを許してください。
employees.html(Djangoテンプレート):
<div class="card-body collapse in">
<div class="card-block card-dashboard">
<button id="addRow" class="btn btn-primary mb-2 js-create-employee"><i class="ft-plus"></i> Add New Employee</button>
<table class="table table-striped table-bordered zero-configuration">
<thead>
<tr>
<th>Name</th>
<th>Username</th>
<th>Roles</th>
<th>Email</th>
<th>Mobile Contact</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for profile in user_profile_list %}
<tr>
{% if not profile.user.is_superuser %}
<td><a href="{% url 'dispatch:profile_detail' pk=profile.user_id %}">{{ profile.user.get_full_name }}</a></td>
<td>{{ profile.user.username }}</td>
<td>
{% for g in profile.user.groups.all %}
<div class="tag tag-default">{{ g.name|split:'_'|title }}</div>
{% endfor %}
</td>
<td>{{ profile.user.email }}</td>
<td>{{ profile.mobile_phone }}</td>
<td><a href="#" alt="Edit"><i class="fa fa-pencil"></i></a> <a href="#" alt="Assign"><i class="fa fa-link"></i><a/> <a href="#" alt="delete"><i class="fa fa-times"></i><a/></td>
{% endif %}
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Username</th>
<th>Roles</th>
<th>Email</th>
<th>Mobile Contact</th>
<th>Actions</th>
</tr>
</tfoot>
</table>
DATATABLEインスタンス:
$(document).ready(function() {
/****************************************
* js of zero configuration *
****************************************/
$('.zero-configuration').DataTable();
});
Jquery.datatables.min.jsとdataTables.bootstrap4.min.jsも使用されるが、それらブートストラップ4から在庫が来ます。私は必要がない限り、ここにそれらを追加するつもりはなく、とにかくミニチュア化されています。
私は理解していますが、データはユーザーごとに異なります。ではなぜそれに問題がありますか? –
ユーザーがスーパーユーザーの場合、この条件では{%if not profile.user.is_superuser%}この問題が発生する可能性があります。番号が
スーパーユーザーコードは、1人の追加ユーザーしかない場合に機能します。テーブルが壊れているユーザーに2番目の非スーパーユーザーを追加するとき –
関連する問題