Wolfzmus Wolfzmus - 1 month ago 10
jQuery Question

datatables click even on last column

I have datatables like this code

var table = $("#mas-vendor");
var filter = $('.form-filter');
var target = table.attr('data-table');
var oTable = table.on( 'processing.dt', function ( e, settings, processing ) {
if (processing) {
$(this).find('tbody').addClass('load1 csspinner');
} else{
$(this).find('tbody').removeClass('load1 csspinner');
};
} ).DataTable({
"ajax": host+'datatable/'+target,
"bServerSide": true,
"iDisplayLength" : 10,
"order": [[ 1, "desc" ]],
"columnDefs": [{
"targets": [ 0 ],
"className": "details-control",
},]
});


and the html like this

<table id="mas-vendor" class="dataTable table table-bordered table-hover table-full-width" width="100%" data-table="masvendor">
<thead>
<tr>
<th>Name</th>
<th>Country</th>
<th>Terms</th>
<th>Cheque/Giro Name</th>
<th>PPN</th>
<th>NPWP</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
</table>


on json like this (just example)

$json['data'][] = [$val['vendor'], $val['country'], $val['terms'], $val['cgname'], $val['ppn'], $val['NPWP'], $val['status'],'<a href="javascript:;" id="delete">Delete</a> || <a href="javascript:;" id="edit">Edit</a>'];


And my problem is i need even click on last column (action) not all column, and how do i know if id is delete or edit. Can someone help me??

i wanna try use this code,

table.find('tbody').on('click', 'td a', function (){});


but i'm still dont know how to use it on last column

Answer

Try this

table.find('tbody').on('click', 'td:last-child a', function (){});

It will make all rows of last column clickable.

Comments