由于每个表的行数少于100,所以实现可排序表最简单的方法是使用名为Dynatable的免费javascript插件。下面给出了实现Dynatable项目的简单方法。
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Dynatable/0.3.1/jquery.dynatable.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Dynatable/0.3.1/jquery.dynatable.min.js"></script>
<script>
$(document).ready(function(){
$('#myTable').dynatable();
});
</script>
<table id="myTable" class="table table-bordered">
<thead>
<tr>
<th><b>NIM</b></th>
<th><b>Nama Lengkap</b></th>
<th><b>Program Studi</b></th>
<th><b>Angkatan</b></th>
<th><b>Status</b></th>
<th><b>Delete</b></th>
</tr>
</thead>
<tbody>
<?php
foreach($anggota as $pengurus){
?>
<tr>
<td><?php echo $pengurus->nim;?></td>
<td><?php echo $pengurus->namalengkap;?></td>
<td><?php echo $pengurus->programstudi;?></td>
<td><?php echo $pengurus->angkatan;?></td>
<td><?php echo $pengurus->status;?></td>
<td>
<a href="<?php echo base_url('admins/pengurus/hapus/'.$pengurus->nim)?>">
<i class="fa fa-times fa-2x" aria-hidden="true"></i>
</a>
</td>
</tr>
<?php }?>
</tbody>
</table>
如果行数增加超过100,则建议使用Data Tables。但是它的实现需要打破你的代码,它有点复杂,不建议用于小尺寸的表格。
记住,您需要在使用它之前导入jquery,并为每个表分配不同的表ID。单击任何表头字段将根据该字段对表进行排序。
欢迎SO。 请阅读[我可以问哪些主题](http://stackoverflow.com/help/on-topic) 和[如何提出一个好问题](http://stackoverflow.com/help/how-to - 问) 和[完美的问题](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) 以及如何创建[最小,完整和可验证的例子] (http://stackoverflow.com/help/mcve) – RiggsFolly
我只是简单看看你的代码。在向你建议你的答案之前,我想知道表中的行数。告诉我大概的数量。它是超过100还是小于100. –
@GeordyJames我在tbl_members上有42行字段。它会在稍后增加。 –