1
jQuery
のデータテーブルプラグインをHTML、PHP、MySQL
で使用しています。テーブルのIDを明示的に設定するとすべてが正常ですが、MySQL
の結果をjupleに渡すと、テーブルIDが「理解」されません。たぶん、コードの方がはっきりしています。動作していない動的IDを持つdataTables
<table class="table table-bordered table-striped mb-none" id="datatable-tabletools">
<thead>
<tr>
<th style="width: 60px; text-align: center;">Id</th>
<th style="width: 400px; text-align: center;">Info A</th>
<th style="width: 390px; text-align: center;">Info B</th>
<th style="width: 100px; text-align: center;">Actions</th>
</tr>
</thead>
<tbody>
<!-- tbody dynamically populated -->
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
$('#datatable-tabletools').DataTable({
});
});
</script>
データテーブル:
<?php
foreach ($sections as $section)
{
$insc = Inscripciones::getAllInscriptionBySection($section -> getId());
if (count($insc) > 0)
{
?>
<h2 style="margin-bottom: 50px;"><?php echo $section->getNombre(); ?></h2>
<table class="table table-bordered table-striped mb-none" id="datatable-tabletools-<?php echo $section -> getId(); ?>">
<thead>
<tr>
<th style="width: 60px; text-align: center;">Id</th>
<th style="width: 450px; text-align: center;">Category</th>
<th style="width: 390px; text-align: center;">Title</th>
<th style="width: 140; text-align: center;">Usuario</th>
<th style="width: 100px; text-align: center;">Acciones</th>
</tr>
</thead>
<tbody>
<!-- tbody also dynamically populated -->
</tbody>
</table>
<?php
}
}
?>
<script type="text/javascript">
$(document).ready(function() {
$('#datatable-tabletools-1').DataTable({
});
$('#datatable-tabletools-2').DataTable({
})
$('#datatable-tabletools-3').DataTable({
})
});
</script>
好奇心事がレンダリングソースコード内のテーブルIDは、 "データテーブル-tabletools-1" として示されることがあり、正常に動作
データテーブル"datatable-tabletools-2"など...
ありがとうございます!
ありがとうございました! ...しかし、私は幸運ではありませんでした... –
こんにちは@Pramod、私は新しい、クリーンなスクリプトでクラスを試して、魅力のように動作するので、私は何か他のものを見逃していると思います... –
素晴らしい!共通のデータテーブル初期化コードを持っている限り、クラスはうまくいくはずです。 – Pramod