[eluser]Destreyf[/eluser]
Continued!
The usage for this code is very simple.
Code:
<?php
class Example extends Controller {
function get_data(){
$column_map = array('clock_date','clock_method');
$this->load->library('Datatables');
$this->datatables->addColumn($column_map);
$q = $this->db->where('employee_id','12345')
$data = $this->datatables->get($q,'employee_timecard');
echo json_encode($data);
}
}
A basic explanation would that you build you query, outside of the datatables library (using models, ect) and once you get it to the point where you're ready, assign it to a variable and pass it in as an argument, along with the table name, it will automatically build all of the order by columns, and the searches.
Some alternative syntax is as follows:
Code:
class Example extends Controller {
function get_data(){
$this->load->library('Datatables');
$data = $this->datatables->get($this->db->where('employee_id','12345'),'employee_timecard',array('clock_date','clock_method'));
echo json_encode($data);
}
}
I believe this to be a simple alternative, my setting for jQuery DataTables by Allan Jardine are as follows:
Code:
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/example/get_data.html",
'fnServerData': function(sSource, aoData, fnCallback){
$.ajax({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
});
}
});
});
The code provided here is provided as is, with no warranty - Use at your own risk or advantage, a few notes to be heard.
This does not Currently support the "Non Searchable" and "Non Sortable" options housed by the jQuery DataTables plug-in, but i plan on adding those soon, as well as filling in some additional functionality, however, my free time is sparse, and i figured I'd contribute back to a fantastic community with what little i can.