How to Server side DataTables with Ignited-Datatables Library?
My application use CodeIgniter.
Library that I use is Ignited-datatables Library.
My controller is like this :
public function get_book()
{
$this->datatables->select('id, hotel, city, country, region')
->unset_column('id')
->from('hotel_book')
echo $this->datatables->generate('json', '');
}
My HTML is like this:
<table id="example">
<thead>
<tr>
<th>Hotel</th>
<th>City</th>
<th>Country</th>
<th>Region</th>
</tr>
</thead>
</table>
My Javascript is like this:
<script type="text/javascript">
var table = $('#example').dataTable( {
"order": [[ 1, "asc" ]],
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [ 3 ]},
{ 'bSearchable': true }
],
"Processing": true,
"ServerSide": true,
"sAjaxSource": '<?php echo site_url(); ?>book/get_book',
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayStart ":20,
"oLanguage": {
"sProcessing": "<img src='<?php echo base_url(); ?>assets/images/ajax-loader_dark.gif'>"
},
"columns": [
{ "data": "hotel" },
{ "data": "city" },
{ "data": "country" },
{ "data": "region" }
],
'fnServerData': function(sSource, aoData, fnCallback)
{
$.ajax
({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
});
}
} );
</script>
How to make searching, filter and paging into server side ?
Thank you.
There is error in your Code.
You are missing the Semi Colon before echo. I am using your code and everything is working fine after putting semi colon.