Implementing datatables in codeigniter
Implementing datatables in codeigniter
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:
[code]
$(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'
});
});
Username
Full Name
Office
Position
Email
Privilege
Date Registered
[/code]
model:
[code]
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
}
[/code]
controller:
[code]
public function get_active_users() {
$results = $this->user_management->active(NULL, TRUE);
echo json_encode($results);
}
[/code]
Screenshot: http://imageshack.us/a/img163/6937/93541166.png
views:
[code]
$(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'
});
});
Username
Full Name
Office
Position
Privilege
Date Registered
[/code]
model:
[code]
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
}
[/code]
controller:
[code]
public function get_active_users() {
$results = $this->user_management->active(NULL, TRUE);
echo json_encode($results);
}
[/code]
Screenshot: http://imageshack.us/a/img163/6937/93541166.png
This discussion has been closed.
Replies
[code]
$this->load->model('user_management');
[/code]
is at the constructor and working
There is also https://github.com/IgnitedDatatables/Ignited-Datatables/ .
Also the documentation for server-side processing with DataTables is here:
http://datatables.net/usage/server-side
We are not able to provide support for those libraries here, nor is this the place to ask PHP / CodeIgniter specific questions as you'll be able to get better help else where.
Allan