Getting a TypeError when calling 'fnPreRowSelect' - e is undefined.
Getting a TypeError when calling 'fnPreRowSelect' - e is undefined.
bigsipper
Posts: 31Questions: 2Answers: 0
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]
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]
This discussion has been closed.
Replies
Allan
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.
[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]
Allan