What I Need
*When Ajax is loaded datable is reintailized.
i would explain in steps
No Reinitialize Of datatable.
I just want paging and search should be reintialized.
i have taken help from this url: http://datatables.net/forums/discussion/256/fnreloadajax/p1.
Ajax call code:
   if ($('#teamTable').size() > 0)
    {
        $('#teamTable').dataTable({
            "sPaginationType": "bootstrap"
        });
    }
      $("#save_team").click(function() {
            $.ajax({
            type: "POST",
            url: "asana_team.php",
            data: { people_name: $('#e2').val(), team_name:$('#teamname').val() },
            beforeSend : function(){
                $("#team_table").remove();
                $("#team_table_div").append("<center id=\"loading\" style=\"margin-top:25%;margin-bottom:25%\"><img src='../common/images/ajax-loader.gif' /></center>");
            },
            contentType: "application/x-www-form-urlencoded"
            }).done(function(data) {
                $("#loading").remove();
                $('#team_table_div').append(data);
                $('#teamTable').dataTable({
                    "sPaginationType": "bootstrap"
                });                    
            });
        });
* working fine but i reintializing pagination in datatable no datable is loaded.
i have used this code to reinitailize table.
 function callBack()
 {
 var call= $('#teamTable');
call.dataTable({
 "sPaginationType": "bootstrap",
 "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
 "oLanguage": {
 "sLengthMenu": "_MENU_ records per page"
 } });
}
$(document).ready(function() {
callBack();
});
Remove destroy:true option and instead of destroying and recreating the table use clear() to clear the table content, rows. add() to add the table data and then draw() to re-draw the table. In this case you would need to initialize DataTables once on page initialization. Save this answer.
This error is triggered by passing in options to a DataTables constructor object when the DataTable instance for the selected node has already been initialised. For example: $('#example'). dataTable( { paging: false } ); $('#example').
This worked for me after a lot of research:- First check if dataTable exist or not, if it does then destroy dataTable and recreate it
if ($.fn.DataTable.isDataTable("#mytable")) {
  $('#mytable').DataTable().clear().destroy();
}
$("#mytable").dataTable({...
                       
                });
This worked for me:
First I initalize the datatable, with
$(".myTable").DataTable({ "bDestroy": true, .... });
The "bDestroy" attribute was necessary in my case.
Then when I have something to append dynamically to my table I do the following:
$(".myTable").dataTable().fnDestroy();
//Append stuff to my table
$(".myTable").DataTable({ "bDestroy": true, ... });
Also notice that I use the dataTable() function when destroying the table and the DataTable() function when initalizing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With