Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Controller:
- public function ajax_list()
- {
- $list = $this->Foto_model->get_datatables();
- $data = array();
- $no = $_POST['start'];
- foreach ($list as $data_foto) {
- $no++;
- $row = array();
- $row[] = '<p style="text-align: center">'.$no.'</p>';
- $row[] = '<p style="text-align: left">'.$data_foto->judul_foto.'</p>';
- $row[] = '<p style="text-align: left">'.$data_foto->judul_album.'</p>';
- $row[] = '<p style="text-align: center"><img src="'.base_url('assets/images/foto/').$data_foto->ufile.$data_foto->ufile_type.'" width="100px"></p>';
- $row[] = "
- <p style='text-align: center'>
- <a class='btn btn-sm btn-warning' href='".base_url('admin/foto/update/').$data_foto->id_foto."' title='Edit'><i class='fa fa-pencil'></i> EDIT</a>
- </p>
- <p style='text-align: center'>
- <a class='btn btn-sm btn-danger' href='".base_url('admin/foto/delete/').$data_foto->id_foto."', onClick=\"return confirm('Apakah Anda yakin?');\"><i class='glyphicon glyphicon-trash'></i> HAPUS</a>
- </p>";
- $data[] = $row;
- }
- $output = array(
- "draw" => $_POST['draw'],
- "recordsTotal" => $this->Foto_model->count_all(),
- "recordsFiltered" => $this->Foto_model->count_filtered(),
- "data" => $data
- );
- //output to json format
- echo json_encode($output);
- }
- Model:
- public function get_datatables()
- {
- $this->_get_datatables_query();
- if($_POST['length'] != -1)
- $this->db->limit($_POST['length'], $_POST['start']);
- $this->db->select('id_foto, judul_foto, judul_album, foto.userfile as ufile,foto.userfile_type as ufile_type');
- $this->db->join('album ', 'album.id_album = foto.id_foto','left');
- $query = $this->db->get();
- return $query->result();
- }
- View:
- <section class="content">
- <div class="box box-primary">
- <div class="box-body table-responsive padding">
- <a href="<?php echo $action_add ?>">
- <button class="btn btn-success"><i class="fa fa-plus"></i> Tambah <?php echo $title ?> Baru</button>
- </a>
- <button class="btn btn-grey" onclick="reload_table()">
- <i class="glyphicon glyphicon-refresh"></i> Refresh
- </button>
- <h4 align="center"><?php echo $this->session->userdata('message') <> '' ? $this->session->userdata('message') : ''; ?></h4>
- <hr/>
- <table id="table" class="table table-striped table-bordered">
- <thead>
- <tr>
- <th style="text-align: center">No.</th>
- <th style="text-align: center">Judul Foto</th>
- <th style="text-align: center">Album</th>
- <th style="text-align: center">Foto</th>
- <th style="text-align: center">Aksi</th>
- </tr>
- </thead>
- <tbody></tbody>
- </table>
- </div>
- </div>
- </section>
- <!-- DATA TABLES SCRIPT -->
- <script src="<?php echo base_url('assets/plugins/datatables/jquery.dataTables.min.js') ?>" type="text/javascript"></script>
- <script src="<?php echo base_url('assets/plugins/datatables/dataTables.bootstrap.min.js') ?>" type="text/javascript"></script>
- <script type="text/javascript">
- var table;
- $(document).ready(function() {
- table = $('#table').DataTable({
- "processing": true, //Feature control the processing indicator.
- "serverSide": true, //Feature control DataTables' server-side processing mode.
- "bPaginate": true,
- "bLengthChange": true,
- "bFilter": true,
- "bSort": true,
- "bInfo": true,
- "bAutoWidth": false,
- "aaSorting": [[0,'desc']],
- "lengthMenu": [[10, 25, 50, 100, 500, 1000, -1], [10, 25, 50, 100, 500, 1000, "Semua"]],
- // Load data for the table's content from an Ajax source
- "ajax": {
- "url": "<?php echo site_url('admin/foto/ajax_list')?>",
- "type": "POST"
- },
- //Set column definition initialisation properties.
- "columnDefs": [
- {
- "targets": [ -1 ], //last column
- },
- ],
- });
- });
- function reload_table(){
- table.ajax.reload(null,false); //reload datatable ajax
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement