A bit of contrived method for getting hidden column value for a selected row
A bit of contrived method for getting hidden column value for a selected row
I am returning the first column(hidden) which is called "Id" of my table when a row is selected.
Here is my snippet:
$('#tblMyTable tbody').on('click', 'tr', function () {
var tr = $(this).closest('tr');
var row = table.row(tr);
var Id = table.row(row[0][0]).data().Id;
//call some ajax
});
Just curious if this is the best way or if there is a preferred method\ shortcut? I briefed through the docs and did see a cells attribute but did not see it in the debugger walking through the inherited attributes\methods.
Thanks!
This question has an accepted answers - jump to answer
Answers
Ugh, sorry did not notice the syntax for posting code.
I would suggest simply:
You don't need to use
$(this).closest('tr')
asthis
is already thetr
element, based on your jQuery event. You can also use the node (i.e.this
) as the row selector, so line 3 in your code above, and then passing in the index is redundant.Regards,
Allan
Thank you sir, it works perfectly.
I hate to resurface this question but I have been informed I need to stick with the legacy release. What would be the equivalent for getting the hidden column value for the legacy library?
I was looking at fnGetColumnData function but receiving errors that the method is not supported for the object
Disregard found my answer with fnGetData()
Or with the 1.1- use
row().data()
.Allan