Getting a TypeError when calling 'fnPreRowSelect' - e is undefined.

Getting a TypeError when calling 'fnPreRowSelect' - e is undefined.

bigsipperbigsipper Posts: 31Questions: 2Answers: 0
edited January 2014 in DataTables 1.9
http://jsfiddle.net/bigsipper/nwMAP/ http://debug.datatables.net/elukep

I am using an example from a previous discussion to 'disable' row selection on certain columns.
http://datatables.net/forums/discussion/comment/42209

But when I run, it throws a Javascript exception:

TypeError: e is undefined
if ( $(e.srcElement).hasClass('open_modal') ) {

Ummmmm.... this is on a 'click' event, so.... how could the event not be defined?

[code]
"oTableTools": {
"sRowSelect": "os",
"aButtons": [ "select_all", "select_none" ],
"fnPreRowSelect": function ( e, nodes ) {
if ( $(e.srcElement).hasClass('open_modal') ) { //<<< this is where it stops.
return false;
}
return true;
},

[/code]

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    I think that might be a bug. I'm going to do some work on TableTools tomorrow. I'll take a look then.

    Allan
  • bigsipperbigsipper Posts: 31Questions: 2Answers: 0
    Found a clue with some more googling:

    Note that if you simulate row selections in certain ways, like using back/next buttons in the following docs example:

    http://editor.datatables.net/release/DataTables/extras/Editor/examples/back-next.html
    ... That your fnPreRowSelect function will be called with an undefined event. In this case, simply ignore undefined events:

    so I changed the fnPreRowSelect function to this:
    [code]
    "fnPreRowSelect": function ( e, nodes ) {
    if ( e != undefined && $(e.srcElement).hasClass('open_modal') ) {
    return false;
    }
    return true;
    [/code]

    Now I don't get the Javascript exception.... but the row still gets selected and highlighted.
  • bigsipperbigsipper Posts: 31Questions: 2Answers: 0
    ah... http://stackoverflow.com/questions/13602039/e-srcelement-is-undefined-in-firefox) solved it:
    [code]
    "fnPreRowSelect": function ( e, nodes ) {
    // firefox only (see http://stackoverflow.com/questions/13602039/e-srcelement-is-undefined-in-firefox)
    if ( e != undefined && $(e.target).hasClass('open_modal') ) {
    // other browsers should use: if ( e != undefined && $(e.srcElement).hasClass('open_modal') ) {
    return false;
    }
    return true;
    },
    [/code]
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Ah - good stuff. I was totally confused for a minute there, looking through the TableTools code and couldn't find it of course... Thanks for updating this post and good to hear you have a solution!

    Allan
This discussion has been closed.