Including a hidden value in an event
Including a hidden value in an event
Hi there
I think I'm trying to do something simple, but I can't quite find the answer!
I have a row click opening a new page in the same window, with the URL appended with an ID that I get from the table. Got that working OK, but I want to hide the ID column. When I hide it using fnSetColumnVis, the next column value is used rather than column 0, which is the (now hidden) one I want to use.
[code]
var oTable;
$(document).ready( function () {
oTable = $('#datatable0').dataTable({
"sScrollY": "320px",
"bSort": false
});
var nNodes = oTable.fnGetNodes( );
/* Add events */
$('#datatable0 tbody tr').live('click', function () {
var nTds = $('td', this);
var sID = $(nTds[0]).text();
void(
open
('http://url.goes.here.co.uk/edit.php?userid='+sID,'_self','resizable,location,menubar,toolbar,scrollbars,status')
)
} );
/* Hide the first (ID) column after initialisation*/
oTable.fnSetColumnVis( 0, false );
} );
[/code]
I THINK I need to use fnGetNodes instead. What I don't know is how to get the ID from the results of getNodes.
If I use:
[code]
var nNodes = oTable.fnGetNodes( );
[/code]
... and then alert nNodes instead of the open command above to see what's there, when I click I get a list of [Object HTMLTableRowElement] - I'm guessing these are arrays that I need to parse, perhaps.
Can someone please advise if I'm looking in the right direction here, and how I get the ID value I want (which is the first item in every row) in var sID ?
Thank you
I think I'm trying to do something simple, but I can't quite find the answer!
I have a row click opening a new page in the same window, with the URL appended with an ID that I get from the table. Got that working OK, but I want to hide the ID column. When I hide it using fnSetColumnVis, the next column value is used rather than column 0, which is the (now hidden) one I want to use.
[code]
var oTable;
$(document).ready( function () {
oTable = $('#datatable0').dataTable({
"sScrollY": "320px",
"bSort": false
});
var nNodes = oTable.fnGetNodes( );
/* Add events */
$('#datatable0 tbody tr').live('click', function () {
var nTds = $('td', this);
var sID = $(nTds[0]).text();
void(
open
('http://url.goes.here.co.uk/edit.php?userid='+sID,'_self','resizable,location,menubar,toolbar,scrollbars,status')
)
} );
/* Hide the first (ID) column after initialisation*/
oTable.fnSetColumnVis( 0, false );
} );
[/code]
I THINK I need to use fnGetNodes instead. What I don't know is how to get the ID from the results of getNodes.
If I use:
[code]
var nNodes = oTable.fnGetNodes( );
[/code]
... and then alert nNodes instead of the open command above to see what's there, when I click I get a list of [Object HTMLTableRowElement] - I'm guessing these are arrays that I need to parse, perhaps.
Can someone please advise if I'm looking in the right direction here, and how I get the ID value I want (which is the first item in every row) in var sID ?
Thank you
This discussion has been closed.
Replies
From another post:
[code]
var aTrs = oTable.fnGetNodes();
for ( var i=0 ; i
Thanks.
[code]
var aData = oTable.fnGetData( this );
[/code]
inside the event handlers where 'this' is the TR element.
Allan