FnRender limitations

FnRender limitations

gruckgruck Posts: 5Questions: 0Answers: 0
edited July 2011 in General
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.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    There are other callbacks that you can use, like fnDrawCallback

    http://www.datatables.net/ref
  • gruckgruck Posts: 5Questions: 0Answers: 0
    Thanks for the link, quite consise.
    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
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Why can't you change it, or add to it?

    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
  • gruckgruck Posts: 5Questions: 0Answers: 0
    edited July 2011
    I can't change it since this would mess up the existing plugin that is meant to be as generic as possible.

    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]
  • gruckgruck Posts: 5Questions: 0Answers: 0
    Didn't help either...
    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.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited July 2011
    how about an inline handler?

    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.
  • gruckgruck Posts: 5Questions: 0Answers: 0
    inline handler, you mean something like onclick attribute ?

    this is no help when you try to stop propagation of jquery events, unless i missed something somewhere...
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    I think you can: http://stackoverflow.com/questions/387736/how-to-stop-event-propagation-with-inline-onclick-attribute
This discussion has been closed.