Datatable click button ---> row data
by Akram kamal
HTML
<link rel="stylesheet" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">
<script src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<table id="metadataListTable" class="display" border="1" >
<thead>
<tr>
<th title="Interface" id="transInterface" class="header"> <a href="#">Interface</a></th>
<th title="Version" id="transInterface" class="header"> <a href="#">Version</a></th>
<th title="Transfer_type" id="transType" class="header"> <a href="#">Transfer Type</a></th>
<th>More Info</th>
<th title="Edit" class="header"> <a href="#">Edit</a></th>
<th title="Delete" class="header"> <a href="#">Enable/Disable</a></th>
<th title="Disabled" id="disabled" class="header"> <a href="#">Disabled</a></th>
</tr>
</thead>
<tbody>
<tr id='6857'>
<td class="center">dtuip9qt</td>
<td class="center">4.0</td>
<td class="center">HTTPS</td>
<td class="center">
<a href="/Grouping/ShowMetadataDetail.do?metadataID=6857&days=90" style="margin:10px;margin-right:30px;" class="button">View Details</a>
</td>
<td class="center">
<a href="/Grouping/ShowMetadataEdit.do?metadataID=6857&days=90" style="margin:10px;margin-right:30px;" class="button">Edit</a>
</td>
<td class="center">
<a href="#" id="gglobal" style="margin:10px;margin-right:30px;" class="button delete">Disable</a>
...
JavaScript
$(document).ready(function() {
var oTable = $('#metadataListTable').DataTable({
"bStateSave": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bScrollCollapse": true,
});
$(document).on('click','#metadataListTable .delete', function () {
event.preventDefault();
var ans = confirm("Do you want to delete Metadata?");
if(ans==true){
var data = oTable.row($(this).closest('tr')).data();
console.log(data);
//console.log( data[0] +" ========= "+ data[3] );
oTable.cell( $(this).closest('tr'), 6 ).data( 'T' );
oTable.cell( $(this).closest('tr'), 5 ).data('<td class="center"><a href="#" class="button enable" style="margin:10px;margin-right:30px;">Enable</a></td>');
}
});
} );