0

im a newbie for codeigniter. i need some help to solve my problem.

so i have a table filled with data that i GET from database (which only display the last timestamp for category "no_registrasi"). and there is an option in "Selesai" to remove the row in the html table without delete it in database. i already tried to find the solution, but i have no idea how to do this.

this is my table html

<table id="tabel-pas" class="table table-striped table-bordered dt-responsive wrap" cellspacing="0" width="100%">
          <thead>
            <tr>
              <th>Waktu</th>
              <th>No. Registrasi</th>
              <th>No. Rekam Medis</th>
              <th>Nama Dokter</th>
              <th>Nama Pemilik</th>                   
              <th>Nama Hewan</th>                      
              <th>Aksi</th>           
            </tr>
          </thead>
          <tbody>
            <?php
              $no = 1;
              foreach($daftar_inap_aktif as $row){
              echo "<tr>";
              echo '<td>'.$row->waktu.'</td>';
              echo "<td>".$row->no_registrasi."</td>";     
              echo "<td>".$row->no_rm."</td>";
              echo "<td>".$row->username."</td>";
              echo "<td>".$row->nama_pemilik."</td>";
              echo "<td>".$row->nama_hewan."</td>";
              echo '<td>'; 

                echo '<a href="linktoforminap?id='.$row->id.'">Tambah</a> | <a href="#">Selesai</a>';

              echo'</td>';
              echo"</tr>";$no++;
              }            
            ?>
          </tbody>
        </table>

here is my model

function daftar_inap_aktif()
    {
        $this->db->select('*');
        $this->db->select_max('waktu');
        $this->db->from('inputrminap');
        $this->db->group_by('no_registrasi');
        $this->db->order_by('waktu', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }

and here is my controller

function daftar_inap()
    {
        $data['daftar_inap_aktif'] = $this->rekammedis_model->daftar_inap_aktif();
        $this->load->view('daftar_inap_view', $data);
    }
2
  • You can handle it with pure javascript or jQuery, so I added 2 tags. Commented May 21, 2016 at 13:14
  • i assume if i use javascipt or jquery, data from GET method will still be back again if i reload the page? Commented May 21, 2016 at 13:26

3 Answers 3

1

I am not sure what are you trying to accomplish, you mean remove that row for that particular session or permanently until set it to display again by admin or so. Let me give it a shot.

**Removing it temporarily(hiding).. What I would do in that case:

Your View Code:

<a href="<?= base_url().'some_controller/some_method/'.$id; ?>">Selesai</a>';
// Considering that you have base url setup and you have id of that row.

And then in Controller:

Public function some_method(){
$id = $this->uri->segment(3);
$this->some_model->hide_rows_with_id($id);
redirect('url_for_that_view');
}

And finally model:

function hide_rows_with_id($id)
    {
        $this->db->select('*');
        $this->db->select_max('waktu');
        $this->db->from('inputrminap');
        $this->db->where('id !=', $id); // Added this
        $this->db->group_by('no_registrasi');
        $this->db->order_by('waktu', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }

This is just an idea, you may want to add more code to model if "id" is an array.

And of course, if the page is reopened from the scratch, all results will be displayed again. To hide it permanently you can create a new column with name something like "hidden" and insert '1' if was hidden through view.. and then in model:

$this->db->where('hidden !=', 1);
Sign up to request clarification or add additional context in comments.

Comments

0

Add a unique id for each row you have, And link it with the href you have

e.g HTML:

<tr id="row-1">
        <td>xx</td>
        <td>xx</td>
        <td>xx</td>
        <td>xx</td>
        <td>xx</td>
        <td>xx</td>
        <td><a href="#" class="del_row" data-row-id="1">Delete</a></td>
</tr>

Then in your javascript code add something like this:

$('.del_row').on('click', function (e) {
        e.preventDefault();
        var $rowId = $(this).data('row-id');
        $('#row-'+$rowId).remove();
});

Comments

0

So that keep an extra column call status. When its active set it 0 and when its deaxtive set it 1.

So in your query where you load data you have to add new where clause.

WHERE status=0

Note : set status column as int or boolen.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.