Datatable not loading when tablestring loaded in ready function

Datatable not loading when tablestring loaded in ready function

madmaxxxmadmaxxx Posts: 2Questions: 0Answers: 0
edited November 2013 in General
I encountered a problem when I try to load the datatable after I loaded the entire tablestring from an external file using .load().
When I load the table without datatables it workes perfectly fine.
When I paste the tablecode to the same html file I am able to load the datatable without problems.

I need to generate the tablestring in another file and this code has to be loaded in the ready function.

Does anybody have a suggestion how to solve this?

This is my ready(function) code

[code]
$( document ).ready(function() {

$("#div2").load('Ajax/loadTable.php',
{ 'videoId': '<?php echo $video_id ?>'
} );

$('#table_id').dataTable(
{
"iDisplayLength": 100,
"aaSorting": [[0, "asc" ]]
} );

});

[/code]

Replies

  • madmaxxxmadmaxxx Posts: 2Questions: 0Answers: 0
    My genuis friend helped me out with this. The solution was that the datatable load function needs to be exectued in the callback function of the loadTable function.

    [code]

    $("#div2").load('Ajax/loadTable.php',
    { 'videoId': '<?php echo $video_id ?>'
    }, function() {
    $('#table_id').dataTable(
    {
    "iDisplayLength": 100,
    "aaSorting": [[0, "asc" ]]
    } );

    });
    });
    [/code]
This discussion has been closed.