How do I access the data in a row?
How do I access the data in a row?
Hi,
I seem to be going round in circles unable to find information on how I get the data out of a datatables object.
I have a row passed in to me from :
myTable.on( 'click', 'tr', function () {
myFunction($(this));
}
None of the table columns have any HTML5 'data' attributes, no identifying class, there seems nothing I can use to say get me the value for column labelled 'Status'.
$(this) is just a table row element with a bunch of child table data elements with nothing to identify them?
If I assigned column names when initialising the DataTable
"columns": [
{ "data": "FPID" },
{ "data": "Promo_Desc" },
{ "data": "Publication" },
{ "data": "Period" },
{ "data": "Sub_Date" },
{ "data": "Status" }
],
And I now have a selected row, how do I access the actual data by their JSON object names?
Thanks,
1DMF
This question has an accepted answers - jump to answer
Answers
OK, I finally managed to get to some data via...
myDataTable.row($(this)).data().myJSONKey
ie.
myDataTable.row($(this)).data().Status
or
myDataTable.row($(this)).data().Sub_Date
etc..
Have you tried using the
row().data()
method?Allan
Isn't that what I posted I am using?
Sorry, I'm confused can you elaborate on what you mean if
.row($(this)).data().
isn't using row().data() method?
I was having a problem with getting data too...until i changed:
var table = $('#example').dataTable();
var table = $('#example').DataTable();
^with a capital D
Then out of nowhere, this worked:
Maybe you have the same issue?
@1DMF - Apologies, I read your code incorrectly. Looks like you've got it working from your second post :-)
Allan