DataTablesとBootstrapモーダルに2つの問題があります。 (ユーリが解決しよう)ページ1 DataTablesがブートストラップモーダルで正しく初期化されない
後、私はこのテーブルを持っている
- が動的に構築されたボタンを使用することはできません、それは、AJAX要求によって動的に構築され、データが正しくロードされ、必要なときにテーブルが構築されます。 'Manage'および 'Delete'ボタンにはクラスが設定されています。クリックすると、現在のテーブルの上に別のモーダルが表示されます私が2頁に行くとそれは動かないまるでリスナーがないかのように
私はjQueryの下に別のDataTableを初期化する必要がある第二モーダルに初期化しませ
-
は、モーダルで「管理」ボタンが開くはずです。開いたら、別のDataTablesを初期化し、AJAXリクエストからデータを取得する必要がありますが、Chromeデベロッパーツールのネットワークタブでは実行されていません。
問題が発見されました。データテーブルが何らかの理由で初期化されていませんか? jQueryがそこまで動作します 私がここで間違っていることを理解できませんか?
$(document).ready(function(){
$('.valid-tags').on('click', '.manageAutofixes', function(){
$('.autofixes-modal').modal('show');
$('.autofixes-modal').on('shown.bs.modal', function() {
var table = $('.autofixes-table').DataTable({
"ajax": {
"url": "/ajax/getValidTags.php",
"type": "POST",
"data": {
ruleID: ruleID,
type: 'autofixes'
},
},
"columnDefs": [{
"targets": 2,
"render": function(data, type, full, meta){
return '<button class="btn btn-default btn-sm manageAutofixes" type="button">Manage</button> <button class="btn btn-danger btn-sm deleteValid">Delete</button>';
}
}],
destroy: true
});
})
})
});
あなたにボタンを解決するために、(ページに含まれています)私のモーダルのHTML
<div class="modal fade autofixes-modal" tabindex="-1" role="dialog" aria-labelledby="LargeModalLabel" aria-hidden="true" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog modal-wide">
<div class="modal-content">
<div class="modal-header modal-header-custom">
<input class="ruleID" type="hidden"></input>
<button type="button" class="close destroyTable" data-dismiss="modal" aria-hidden="true">x</button>
<h4 class="modal-title">Autofixes</h4>
</div>
<div class="modal-body">
<div class="topBar">
<div>
<input type="text" class="autofix inputTextStyling">
</div>
</div>
<hr>
<table class="table table-striped table-condensed autofixes-table" style="width:100%;">
<thead>
<tr>
<th>Autofix</th>
<th>Manage</th>
</tr>
</thead>
<tbody class="autoFixesTable">
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default destroyTable" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
を使用することができます(アヤックスで)結果をロードするたびにアクションを再バインドする必要がありますか? – Yuri
@Yuriモーダルは同じページにあり、ページをきれいにするために独自のファイルにあります。 – Kieron606
ロード時にインクルードするか、モーダルコンテナを埋めるためにajaxリクエストを行いますか? – Yuri