FnRender limitations
FnRender limitations
Hello,
My goal is to add a column that shows a checkbox at the start of each row and some kind of master checkbox un the table header to rule them all. I currently am in trouble with event propagation of events trigered by these cheeckboxes
FnRender works great to add the chekbox on that row.
[code]"fnRender" : function (oObj){
return $('').append(
$('').attr('type','checkbox')
.attr('enabled', false)
).html();
}[/code]
But since my row should be clickable, i must add a click handler on these checkbox to prevent propagation. fnRender only allows me to add the raw html, hence, the click handler cannot be passed (at least easily).
[code].click(function(e){e.stopPropagation();})[/code]
Since we ony get the html code to be returned by the fnRender function, this handler isn't set anymore
I tried accessing to the tr node by using oObj.oSettings.oInstance.fnGetNodes(oObj.iDatarow) but at the time of the rendering, that node doesn't exists yet.
I wouldn't rather not use the fnrowCallback since this is already used by some other homemade plugins.
Do you have any idea on how I could either :
+ Access the node at rendering time so that i can add the click handler to prevent propagation
+ Pass along the click handler to be set in the string return by the function affected to fnRender
Thanks for your time and suggestions.
My goal is to add a column that shows a checkbox at the start of each row and some kind of master checkbox un the table header to rule them all. I currently am in trouble with event propagation of events trigered by these cheeckboxes
FnRender works great to add the chekbox on that row.
[code]"fnRender" : function (oObj){
return $('').append(
$('').attr('type','checkbox')
.attr('enabled', false)
).html();
}[/code]
But since my row should be clickable, i must add a click handler on these checkbox to prevent propagation. fnRender only allows me to add the raw html, hence, the click handler cannot be passed (at least easily).
[code].click(function(e){e.stopPropagation();})[/code]
Since we ony get the html code to be returned by the fnRender function, this handler isn't set anymore
I tried accessing to the tr node by using oObj.oSettings.oInstance.fnGetNodes(oObj.iDatarow) but at the time of the rendering, that node doesn't exists yet.
I wouldn't rather not use the fnrowCallback since this is already used by some other homemade plugins.
Do you have any idea on how I could either :
+ Access the node at rendering time so that i can add the click handler to prevent propagation
+ Pass along the click handler to be set in the string return by the function affected to fnRender
Thanks for your time and suggestions.
This discussion has been closed.
Replies
http://www.datatables.net/ref
I am aware of fnDrawCallback, but same as fnRowCallback, you can't add several .... and there is alredy one added by a plugin i cannot change
how about using jquery's .live function?
another thing you could try, though I don't think it's the best idea, is to add your handlers in a delay call using setTimeout
jQuery live events cannot have their propagation stopped. Althought it would have helped me alot this time.
I didn't think about delaying the addition of the handler. i'll try it if i find nothing else.
I am currently trying to append some that will add the handler to the checkbox at display time
[code]
"fnRender" : function (oObj){
return $('')
.append( $('').attr('type','checkbox').attr('id', "someID") )
.append($(' $("#someid").click(...))'))
.html();
}
[/code]
The script i wanted to add is exectued before the checkbox can be retrieved via selector ($("#someid").length === 0) ....
If you have any idea, i still am looking for some workarround.
I know your frustration. it would be nice if fnRender could also have be passed a reference to the TD cell object, since you can't get it from the DOM yet.
this is no help when you try to stop propagation of jquery events, unless i missed something somewhere...