I have build a filter in my DataTable so I can check for the status. I am using the following code to retrieve the status:
if(isset($_POST['status']))
{
if (!empty($where) ) {
$where .= "AND status = '". $_POST['status'] ."'";
} else {
$where .= "WHERE status = '". $_POST['status'] ."'";
}
}
else{
if (!empty($where) ) {
$where .= "AND status = '1'";
} else {
$where .= "WHERE status = '1'";
}
}
I have no issues with selecting the data. When I look at the WebConsole I can see that the script is posting the right data en gets the right response.
But I have some issues with the presentation of the data.
When the response is correct I want to update my DataTable.
I am using the following code for updating my datatable:
success:function(data){
$('#tb1').DataTable(data);
}
When I execute this code I get a DataTables warning:
DataTables warning: table id=tb1 - Cannot reinitialise DataTable.
I cant figure out whats wrong with my script. Looking to multiple examples the script should work. Does someone know what is wrong with my script and how I can solve this problem?
Here is my full script:
<script type="text/javascript">
$( document ).ready(function() {
$('#tb1').DataTable({
"bprocessing": true,
"serverSide": true,
"ajax": {
"url": "./Response1.php",
"type": "POST",
"error": function(){
$("#grid_processing").css("display","none");
}
}
});
$("div.toolbar1").html('<select id="status" type="status"><option value="1">Active</option><option value="0">Inactive</option></select>');
$("#status").on('change',function () {
var val = $(this).val();
$.ajax({
url: './Response1.php',
type: 'POST',
data: 'status='+val,
success:function(data){
$('#tb1').DataTable(data);
}
});
});
});
</script>