datatable killing function

datatable killing function

Kode3Kode3 Posts: 5Questions: 0Answers: 0
edited August 2010 in General
Whenever I use datatable all my td onclick functions quit working.

For example this works:
[code]
$(document).ready(function() {

$("#example td").click(function(e) {
var currentCellText = $(this).text();
alert (currentCellText);
});

} );
[/code]

But when I do this it quits working:
[code]
$(document).ready(function() {

$("#example td").click(function(e) {
var currentCellText = $(this).text();
alert (currentCellText);
});

var oTable = $('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"bSortClasses": false,
"sAjaxSource": "get_the_data.php"
} );

} );
[/code]

I know it's probably something simple but I can't figure it out. I'd pull my hair out if I wasn't already bald.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Try using a live event. DataTables is creating DOM elements when you use server-side processing, on each draw - so the elements don't have your event attached. See the first question on the top right here: http://datatables.net/faqs

    You can also use Visual Event to see what elements have event handlers attached to them: http://www.sprymedia.co.uk/article/Visual+Event

    Allan
  • Kode3Kode3 Posts: 5Questions: 0Answers: 0
    Visual Event ... Genious! Thanks for it!

    Not checking jQuery version on a new website ... Idiotic! All my problems are solved now that I checked the basics ... ARG!

    BTW, I had read those pages. But nothing I did worked. And now we know why.

    Thanks Allan!
This discussion has been closed.