jQuery Datatable Server Side Processing with codeigniter

jQuery Datatable Server Side Processing with codeigniter

In this Post We Will Explain About is jQuery Datatable Server Side Processing with codeigniter With Example and Demo.Welcome on Live24u.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Data table Server Side Processing with codeigniter Example

In this post we will show you Best way to implement Datatable demo (Server side) in codeigniter,Mysql and Ajax, hear for DataTables – Development – server-side processing using codeigniter with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.




Controllers – crud.php

<?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class Crud extends CI_Controller {  
      //Codeigniter functions  
      function index(){  
           $data["title"] = "codeigniter c.r.u.d. with modals & ajax free download";  
           $this->load->view('crud_view', $data);  
      }  
      function get_student(){  
           $this->load->model("ci_crud_model");  
           $getStud_data = $this->ci_crud_model->make_datatables();  
           $data = array();  
           foreach($getStud_data as $data_row)  
           {  
                $stud_arr = array();  
                $stud_arr[] = '<img src="'.base_url().'upload/'.$data_row->image.'" class="img-thumbnail" width="100" height="30" />';  
                $stud_arr[] = $data_row->student_fname;  
                $stud_arr[] = $data_row->student_lname;  
                $stud_arr[] = '<button type="button" name="update" id="'.$data_row->id.'" class="btn btn-warning btn-xs">Update</button>';  
                $stud_arr[] = '<button type="button" name="delete" id="'.$data_row->id.'" class="btn btn-danger btn-xs">Delete</button>';  
                $data[] = $stud_arr;  
           }  
           $output = array(  
                "draw"                    =>     intval($_POST["draw"]),  
                "recordsTotal"          =>      $this->ci_crud_model->get_student_list(),  
                "recordsFiltered"     =>     $this->ci_crud_model->get_stud_filterData(),  
                "data"                    =>     $data  
           );  
           echo json_encode($output);  
      }  
 }  

Models – ci_crud_model.php

 <?php  
 class Crud_model extends CI_Model  
 {  
      var $table = "students";  
      var $select_column = array("id", "student_fname", "student_lname", "image");  
      var $order_column = array(null, "student_fname", "student_lname", null, null);  
      function student_query()  
      {  
           $this->db->select($this->select_column);  
           $this->db->from($this->table);  
           if(isset($_POST["search"]["value"]))  
           {  
                $this->db->like("student_fname", $_POST["search"]["value"]);  
                $this->db->or_like("student_lname", $_POST["search"]["value"]);  
           }  
           if(isset($_POST["order"]))  
           {  
                $this->db->order_by($this->order_column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);  
           }  
           else  
           {  
                $this->db->order_by('id', 'DESC');  
           }  
      }  
      function make_datatables(){  
           $this->student_query();  
           if($_POST["length"] != -1)  
           {  
                $this->db->limit($_POST['length'], $_POST['start']);  
           }  
           $get_query = $this->db->get();  
           return $get_query->result();  
      }  
      function get_stud_filterData(){  
           $this->student_query();  
           $get_query = $this->db->get();  
           return $get_query->num_data_rows();  
      }       
      function get_student_list()  
      {  
           $this->db->select("*");  
           $this->db->from($this->table);  
           return $this->db->count_all_results();  
      }  
 }  

Include External Script

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<!-- Devloped by live24u.com free download examples -->  
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>  
<!-- Devloped by live24u.com free download examples -->
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>            
<!-- Devloped by live24u.com free download examples -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />  

Views – crud_view.php

<html>  
 <head>  
   <title><?php echo $title; ?> Live24u.com</title>   
 </head>  
 <body>  
 <!-- Devloped by live24u.com free download examples -->
      <div class="container box">  
           <h3 align="center"><?php echo $title; ?></h3><br />  
           <div class="table-responsive">  
                <hr />  
                <table id="student_data" class="table">  
                     <thead>  
                          <tr>  
                               <th width="20%">Student Image</th>  
                               <th width="20%">Student First Name</th>  
                               <th width="20%">Student Last Name</th>  
                               <th width="15%">Student Edit</th>  
                               <th width="20%">Student Delete</th>  
                          </tr>  
                     </thead>  
                </table>  
           </div>  
      </div>  
 </body>  
 </html>  
 

script.js

 $(document).ready(function(){  
      var dataTable = $('#student_data').DataTable({  
           "processing":true,  
           "serverSide":true,  
           "order":[],  
           "ajax":{  
                url:"<?php echo base_url() . 'crud/get_student'; ?>",  
                type:"POST"  
           },  
           "columnDefs":[  
                {  
                     "targets":[0, 3, 4],  
                     "orderable":false,  
                },  
           ],  
      });  
 });  

style.css

body  
{  
	margin:0;  
	padding:0;  
	background-color:#3a3d3b;  
}  
.box  
{  
	width:850px;  
	padding:30px;  
	background-color:#3d3d3d;  
	border:1px solid #4d4ds4;  
	border-radius:8px;  
	margin-top:12px;  
}  

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Also Read :   NodeJS RESTful CRUD API and MYSQL - node js Restify Tutorial





Example

I hope you have Got What is Server-side DataTables in Codeigniter using jQuery And how it works.I would Like to have FeedBack From My Blog(live24u.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(live24u.com) Are Most Always Welcome.