私はmysqlクエリを実行するコントローラページが1つあるサイトです。結果はm_analitica.php
という名前のビューアページに出力され、上部にはinclude("header.php")
、下部にはinclude("footer")
と表示されます。 footer.php
でbody要素の閉鎖前に、次にBootstrap dataTableはPHPテーブルでソートして検索していません
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="../public/js/DataTables-1.10.12/media/css/dataTables.bootstrap.min.css" />
<link href="../public/css/bootstrap.min.css" rel="stylesheet"/>
<script src="../public/js/bootstrap.min.js"></script>
<script src="../public/js/DataTables-1.10.12/media/js/jquery.dataTables.min.js"></script>
<script src="../public/js/DataTables-1.10.12/media/js/dataTables.bootstrap.min.js"></script>
私は:
m_analitica.php
のためのコード:私は以下のjsスクリプトやCSSを含まheader.php
のヘッドで
<div>
<table class="table table-striped table-bordered table-hover" id="myTable">
<div><h2>Mapa Analítica</h2></div>
<thead>
<tr>
<th>Name</th>
<th>Tipo Documento</th>
<th>Número</th>
<th>Cliente</th>
<th>Obra</th>
<th>Designação</th>
<th>Agregado</th>
<th>Quantidade (ton)</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Tipo Documento</th>
<th>Número</th>
<th>Cliente</th>
<th>Obra</th>
<th>Designação</th>
<th>Agregado</th>
<th>Quantidade (ton)</th>
</tr>
</tfoot>
<?php foreach ($positions as $position): ?>
<tbody>
<tr>
<td><?= $position["data"] ?></td>
<td><?= $position["tipo"] ?></td>
<td><?= $position["num"] ?></td>
<td><?= $position["cliente"] ?></td>
<td><?= $position["obra"] ?></td>
<td><?= $position["nome_obra"] ?></td>
<td><?= $position["agr"] ?></td>
<td><?= $position["ton"] ?></td>
</tr>
</tbody>
<?php endforeach ?>
</table>
スクリプトを挿入しました:
<script type="text/javascript">
$('#myTable').dataTable();
</script>
テーブルをページに分割せず、検索と並べ替えが機能しない場合は、クリックするだけで何もしません。
ブートストラップdataTableはphpで動作しませんか?またはforeachループで?またはコードに何か問題があります。
https://datatables.net/examples/data_sources/server_side.htmlそれに従ってください。 –
私は以前にそれを試しました。 –