I can access the data row by the following simple method:
$('#received-body tr').click( function(){
aData = received_table.fnGetData(this);
selected_received_id = aData[0];
alert( selected_received_id );
});
but I can't access them from the button called .received-update
in one of the rows:
$('#received-body .received-update').click( function(){
alert( 'update' ); // works
aData = received_table.fnGetData( $(this).parents('tr')); // fails
selected_received_id = aData[0];
alert( 'update:' + selected_received_id );
});
Any help appreciated
You may need to use closest as parents() might be giving more then one rows. While closest get the first match up the DOM hierarchy.
You can solve your problem by replacing
with
This same syntax is also required for calls to
received_table.fnGetPosition()
Below piece of code will help,
Try
.parent()
instead of.parents()
because.parents()
get the parent of each element in the current set of matched elements..parent()
will only work if the tr is a direct children of the tr. In that scenario.closest()
will be ideal as shown below.If above didn't work out for you, try filter method to reduce the set of matched elements.
@Stephen Brown, could you please provide the solution if you found how to get the value. I am having exactly the same problem. I have already tried all the ways in this post but no luck. I have the following code.
and the function is (studentDataTable is the datatable)
The console.log print the following
I tried $(tr) , tr and many other ways but it always throws the error TypeError: a.nodeName is undefined ...ta[d]!==m?c.aoData[d]._aData:null}return Y(c)};this.fnGetNodes=function(a){var b...
Any help is much appreciated
Edit
Got it working this way (not sure what I was doing wrong before)
and the function
Not the answer you're looking for? Browse other questions tagged jquery datatables or ask your own question.
asked
viewed
9,078 times
active
1 year, 9 months ago
Linked
Related
Hot Network Questions