I am new to datatables and like it and want to learn more.
My current issue is with communicating with the database. I can get all the data but some of the features are not wroking(e.g. pagination, the entries per page, the search, the search per column).
Here is my fiddle that is fairly basic.
I have included the tbody
tag with 2 rows, for testing, of data which the search and column search works for. My difficulty is getting it to work with database data.
So in my example where I connect to a db,it is slightly different from the above fiddle. It has a index3.php
file, which points to a employee-grid-data3.php
file
Below Code in my index.php that points at employee-grid-data3.php
for connectin to db
<script type="text/javascript" language="javascript" >
$(document).ready(function() {
var dataTable = $('#employee-grid').DataTable( {
"processing": true,
"serverSide": true,
"ajax":{
url :"employee-grid-data3.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".employee-grid-error").html("");
$("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server -- startagain1-index3.php </th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
}
}
} );
} );
</script>
my employee-grid-data3.php
looks exactly like this code here, which I got from this answer here.
Now the data loads from the database but the pagination, the entries per page, the search, the search per column does not seem to comunicate with the db.
Based on what I have provided is there a way to advise me how I can get it working?
For instance, does it have to do with this snippet of code below from employee-grid-data3.php
, in that what I am returning is not completely aligned with what I am expecting to receive.
/*
* Output
*/
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
edit1 useful links: https://datatables.net/manual/tech-notes/1 - after looking at the faq was led here