【发布时间】:2019-06-11 06:20:52
【问题描述】:
我正在尝试为我的表使用数据表插件,但它不起作用
我已经在这个网站上尝试了一些答案,但仍然不起作用
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js" type="text/javascript"></script>
还有这张桌子
<table id="example" class="table table-hover table-striped table-bordered text-center">
<thead>
<tr>
<th>No</th>
<th>Id Transaksi</th>
<th>No Kuitansi</th>
<th>Nama Barang</th>
<th>Kuantitas</th>
<th>Harga</th>
<th>Tanggal</th>
<th>Keterangan</th>
<th colspan="2">Opsi</th>
</tr>
</thead>
<tbody>
<?php
$list = stokORM::find_many();
$i=1;
foreach($list as $stk) :
$brg = $stk->barang()->find_one();
$trx = $stk->transaksi()->find_one();
?>
<?php
$tgl = new carbon($trx->tanggal);
?>
<tr>
<td><?= $i++;?></td>
<td><?= $stk->trx13_id;?></td>
<td><?= $trx->no_kuitansi;?></td>
<td><a href="lihat_perbarang.php?id=<?= $brg->id;?>">
<?= $brg->nama;?></td>
<td><?= $stk->qty.' '.$brg->satuan;?></td>
<?php
if($trx->jenisTrx == 0){
echo "<td>".rupiah($trx->hargaJual)."</td >";
} else {
echo "<td>".rupiah($trx->harga)."</td>";
}
?>
<td><?= $tgl->format('d/m/Y');?></td>
<td><?php
if($stk->jenisTrx == 0){
echo "Penjualan";
} else {
echo "Pembelian";
}
?>
</td>
<?php
if($stk->jenisTrx == 0) {
echo "<td colspan='2'><a style='color:blue;' href='laba-rugi.php?id=$brg->id'>
Cek Laba Rugi
</a></td>";
} else {
echo "<td><a style='color:blue;'href='jual-barang.php?id=$trx->id'>
Jual
</a></td>";
}
?>
</tr>
</tbody>
<?php endforeach;?>
</table>
以及最后的脚本
<script type="text/javascript">
$(document).ready(function() {
$('#example').DataTable();
} );
</script>
我希望它能够正常工作,就像我可以进行实时搜索一样,我可以对记录进行排序和分页 对不起,我的英语不好。 提前致谢
【问题讨论】:
-
你可以尝试在 tbody 关闭之前输入
<?php endforeach;?>吗? -
另外,在某些情况下,
thead和tbody之间的单元格数量可能不同(尤其是在$stk->jenisTrx !== 0时)。 -
@Sanjundev 我试过了,但什么也没发生,还是一样的错误,但现在解决了,因为我的colspan,谢谢你的评论。
标签: javascript php jquery datatables