Including a hidden value in an event

Including a hidden value in an event

Cog1Cog1 Posts: 7Questions: 0Answers: 0
edited December 2011 in General
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

Replies

  • Cog1Cog1 Posts: 7Questions: 0Answers: 0
    Getting closer.

    From another post:
    [code]
    var aTrs = oTable.fnGetNodes();
    for ( var i=0 ; i
  • Cog1Cog1 Posts: 7Questions: 0Answers: 0
    Any ideas, anyone? I've tried a few more things but still can't get the data I need into the event!

    Thanks.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    edited December 2011
    I think all you need to do is:

    [code]
    var aData = oTable.fnGetData( this );
    [/code]

    inside the event handlers where 'this' is the TR element.

    Allan
  • Cog1Cog1 Posts: 7Questions: 0Answers: 0
    Thank you Allan, I'll try that now.
  • Cog1Cog1 Posts: 7Questions: 0Answers: 0
    Perfect! And so simple... thank you.
This discussion has been closed.