2017-01-11 96 views
0

如何让php codeigniter代码根据用户需求进行“排序表”功能。如何对php表格进行排序php codeigniter

我已在模型上查询我最后的web项目(https://github.com/HermesED/KharismaArt

型号:Project_Model

控制器:管理员(DIR)/ pengurus

查看:管理员(dir)/pengurus_admin.php

对不起,指导你们github,因为Idk如何在这里发布代码。

它对英文排序表字段'NIM'或('Student_Id')起作用。但这是编码的“自动”。我想做手动功能,就像在MS Excel中排序表的东西一样

但我真的不知道在视图中为排序表创建功能。

谁能帮助?或者你有一些有用的网站的参考?

+1

欢迎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

+0

我只是简单看看你的代码。在向你建议你的答案之前,我想知道表中的行数。告诉我大概的数量。它是超过100还是小于100. –

+0

@GeordyJames我在tbl_members上有42行字段。它会在稍后增加。 –

回答

0

由于每个表的行数少于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。单击任何表头字段将根据该字段对表进行排序。