Hello everyone! I have a working datatables in plain php a few months ago. Now that I'm studying CodeIgniter, I want to implement datatables server side. The problem is how do I do it? I have this following code.
views:
model:
controller:
Screenshot: http://imageshack.us/a/img163/6937/93541166.png
views:
<script type="text/javascript"> $(document).ready(function() { $('#users_table').dataTable({ "sScrollX": "100%", "sScrollXInner": "100%", "sPaginationType": "full_numbers", "bProcessing": true, "bServerSide": true, "bJQueryUI": true, "bDeferRender": true, "sAjaxSource": '<?php echo base_url(); ?>/users/get_active_users' }); }); </script> <table id="users_table"> <thead> <tr> <th>Username</th> <th>Full Name</th> <th>Office</th> <th>Position</th> <th>Email</th> <th>Privilege</th> <th>Date Registered</th> </tr> </thead> <tbody></tbody> </table>
model:
public function active() { $query = $this ->db ->select('username, last_name, office, email, privilege, datetime_registered') ->where('status', 'Active') ->where('username !=', $this->session->userdata('username')) ->get('users'); return $query->result(); //return result to array }
controller:
public function get_active_users() { $results = $this->user_management->active(NULL, TRUE); echo json_encode($results); }
Screenshot: http://imageshack.us/a/img163/6937/93541166.png