4

I am getting the error "cannot read property 'ntr' of undefined" when i perform mouseover function on a data-table when the data is not present. It works fine when the table is populated. The code is as follows:

$('#example_table tbody td').live('mouseover mouseout', function(event) { 
if (event.type == 'mouseover') {// do something on mouseover 
    console.log('inside mouseover');
    var iPos = oTable.fnGetPosition( this ); // getting error in this line
    if(iPos!=null){
        console.log(iPos);
        var iCol= iPos [1];
    }
}
});

What check should i do so that i dont get this error

Thanks

user2680900
  • 171
  • 2
  • 11

1 Answers1

1

You could check if your table is populated, and if not return:

$('#example_table tbody td').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseover') {// do something on mouseover 
    console.log('inside mouseover');

    // check if you have data in your table
    if (oTable.fnGetData().length <= 0) { // or some similar check
      return;
    }

    var iPos = oTable.fnGetPosition( this ); // getting error in this line
    if(iPos!=null){
      console.log(iPos);
      var iCol= iPos [1];
    }
  }
});
intuitivepixel
  • 23,302
  • 3
  • 57
  • 51