Call fnGetData from outside (and with no var for the table)
Call fnGetData from outside (and with no var for the table)
Rockb
Posts: 97Questions: 0Answers: 0
In my local test-area I use this
[code]$(document).ready( function () {
oTable = $('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );[/code]
and something like this
[code]oTable.$('tr').click(function ()[/code]
to capture the ID of the first column. This works fine!
BUT with the tablepress-plugin for WordPress, which is basically using your 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.
Is there any other way to get the click on the table? Something like:
[code]$('#example tr').click(function ()[/code]
I hope there is an easy and simple way ;-)
[code]$(document).ready( function () {
oTable = $('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );[/code]
and something like this
[code]oTable.$('tr').click(function ()[/code]
to capture the ID of the first column. This works fine!
BUT with the tablepress-plugin for WordPress, which is basically using your 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.
Is there any other way to get the click on the table? Something like:
[code]$('#example tr').click(function ()[/code]
I hope there is an easy and simple way ;-)
This discussion has been closed.
Replies
If the table already exits, DataTables will just use that original instance.
Allan
The modified start position is:
[code]$(document).ready( function () {
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );[/code]
...so without the "oTable = ". If I simple add the
[code]$('#example').dataTable()[/code]
infront of the click-function, it doesn't work. Or what do you exactly mean by that suggested code-line? As a single relating it will miss the "tr".
$('#example tr').click(function () {
var data = $('#example').dataTable().fnGetData( this );
... // do something with the data
} );
[/code]
Allan
After changing to the new versions and newest nightly-downloads this...
[code]$('#example tr').click(function () {
var data = $('#example').dataTable().fnGetData( this,0 );
});[/code]
allows only to click the thead (!) instead of the normal rows - for sure with no result. If change to...
[code]$('#example tbody').click(function () {
var data = $('#example').dataTable().fnGetData( this,0 );
});[/code]
...so with tbody, it handles also the click, but the values in 'data' are again empty. What has happened?
changing to
`$('#example tbody').on('click','tr',function ()
fixed it. I hope^^
Sounds like its a jQuery event listener issue more than a DataTables one. You just need the right combination of selectors and handlers - and that one, in your last post, looks perfect to me.
Allan