0

How to make php codeigniter codes to make feature to 'sort table' by user needs.

I have set the query in models on my final web project (https://github.com/HermesED/KharismaArt)

Models: Project_Model

Controller: admin(dir)/pengurus

View: Admins(dir)/pengurus_admin.php

Sorry for directing you guys to github, because Idk how to post codes here.

It works on sorting table field 'NIM' or ('Student_Id') in English. But that's "automatic" from coding. I want to make manual feature, like in sorting table things just like MS Excel

But I really don't have idea to create feature for sorting table in views.

Can anyone help? Or do you have some useful website for references?

3

2 Answers 2

1

Try editable jquery it's provide sorting, pagination and search feature.

https://editor.datatables.net/examples/inline-editing/simple

i hope it's works

Sign up to request clarification or add additional context in comments.

Comments

0

As the number of rows of each table is less than 100 the easiest way to implement sortable table is by using a free javascript plugin named Dynatable.The simple way to implement Dynatable your project is given below.

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

If the number of rows increases more than 100 then Data Tables is recommended. But its implementation needs to break your codes and it is a little complicated and not recommended for tables with small sizes.

Remember you need to import jquery before using it and for every table assign different table ids. Clicking on any table header field will sort the table according to that field.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.