Question

In my local test-area and as a standalone-script I use this

$(document).ready( function () {
oTable = $('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );

and something like this

oTable.$('tr').click(function ()

to capture the ID of the first column in DataTables. This works fine! BUT with the tablepress-plugin for WordPress, which is basically using DataTables, I cannot add (in this case) "oTable = " to the relating table I whish. This is really odd.

The only way is to change the "core" of the plugin, but that's nasty. So I have to place the 2nd part somewhere else on the page (which is no problem). Is there any other way to get the click on the table? Something like:

$('#example tr').click(function ()

I hope there is an easy and simple way like this ;-)

Was it helpful?

Solution

This works:

$(document).ready( function () {
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );

and

$('#example tr').click(function () {
var data = $('#example').dataTable().fnGetData( this );
});

OTHER TIPS

As far as i know there is some attribute in tbody tag of datatables for example

<tbody role="alert" aria-live="polite" aria-relevant="all">

you can check if your tables have these attr too, if so you can select like this

$('#example tbody[role="alert"] tr').click(function (){});

you can also use this

var oTable2 = $('#example').dataTable();
$('tr',oTable2).click(function ()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top