Reputation: 1666
I have created link in datatable as:
$('#example').dataTable( {
"columnDefs": [ {
"targets": 1,
"render": function ( data, type, full, meta ) {
return '<a href="'+data+'" data-id="'+full.id+'">Download</a>';
}
} ]
} );
I can access id
on clicking <a>
tag using jQuery click
event, but I have several fields to access. And I don't want to use data-
attribute to access each field.
How can I access row object i.e.(full
) , in jQuery event ?
What I have tried is:
"render": function ( data, type, full, meta ) {
alert(full);
return '<a href="'+data+'" data-full="'+full+'">Download</a>';
}
In jQuery event alert( $(this).data('full') );
I can see only [Object object]
.
I have tried to convert it to String but no success.
Upvotes: 0
Views: 1748
Reputation: 58880
Use row().data()
API method to get data for any given row.
For example:
$('#example').on('click', 'tbody a', function(){
var $tr = $(this).closest('tr');
var data = table.row($tr).data();
console.log(data);
});
See this example for code and demonstration.
Upvotes: 1
Reputation: 639
Try jquery .data() to set / get data
$(your_component).data("full", full)
or
JSON.stringify(full) // convert json to string
Upvotes: 0