"dataTable is not a function": tiny issue with click, load and fnGetData

I have an error fetching a row-value by DataTable. Firebug informs after clicking:

TypeError: $(…).dataTable is not a function

An example you can find here on my test-site. So what’s all about? Basically the script shell grap the ID (the 2nd column) of the selected row and then it shell load a page (with this ID as a variable) via load().

The strange part: It can’t be a big deal, cause I’m using exactly the same script at a different website (there the datatable-script is included manually, here by the wordpress-plugin tablepress)… but the relating IDs are correct, I guess.

<script>

window.onload = function() {    

var id1_url = "";

if(id1_url == "" || id1_url == null)
    {
    id1 = "000265";
    id2 = "000213";
    }
    else
        {
        id1 = "";
        id2 = "";
        $(window).scrollTo('#ma', {duration:2000} );    
        }
;

$( "#ma" ).load( "/ma_rs.php", { "id1": id1, "id2": id2 } );
};

                $('#tablepress-1 tbody').on('click','tr',function ()
                    {
                    isClicked=$(this).data('clicked');
                    if (isClicked) {isClicked=false;} else {isClicked=true;}
                    $(this).data('clicked',isClicked);  

                    if(isClicked)
                    {
                        id2 = id1;
                        id1 = $('#tablepress-1').dataTable().fnGetData( this,1 );                                           

                        $( "#ma" ).fadeOut('fast', function() {
                        $( "#ma" ).load("/ma_rs.php", { "id1": id1, "id2": id2 }).fadeIn('slow');
                        });                 
                        $(window).scrollTo('#ma', {duration:2000} );    
                    }               
                    else
                        {
                            id2 = id1;  
                            id1 = $('#tablepress-1').dataTable().fnGetData( this,1 );                           

                            $( "#ma" ).fadeOut('fast', function() {
                            $( "#ma" ).load("/ma_rs.php", { "id1": id1, "id2": id2 }).fadeIn('slow');
                            }); 
                            $(window).scrollTo('#ma', {duration:2000} );
                        }                   
                    }
                );

</script>

So Firebug points to this line after “if(isClicked)”, which is obviously a bad request:

id1 = $('#tablepress-1').dataTable().fnGetData( this,1 );

Have anybody an idea, what’s wrong? “#tablepress-1” is the ID of TablePress’ Table and “dataTable()” the Name of the js by DataTables and should also be right. It would be really great, if you could help me! Thank you.

Read more here: "dataTable is not a function": tiny issue with click, load and fnGetData

Leave a Reply

Your email address will not be published. Required fields are marked *