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

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

RockbRockb Posts: 97Questions: 0Answers: 0
edited July 2014 in Free community support

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

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

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("/s.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("/s.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.

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    if(isClicked) :

    your "if" condition looks the same as your "else" condition to me. That can't be helping when debugging.

  • RockbRockb Posts: 97Questions: 0Answers: 0

    No, that's fine (works perfectly on the different installation I mentioned) and has nothing to do with the issue.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Your "if" condition is the same as your "else" condition. Maybe that has nothing to do with your issue, but it's surely not "fine".

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    edited July 2014

    We'd probably need a link to a test case showing the issue to be able to be much help here. One possibility is that jQuery's noConflict option has been used and $ !== jQuery. Another, possibly more likely option, particularly if you are using WordPress, is that jQuery is being loaded multiple times on the page.

    Allan

This discussion has been closed.