I want to edit/delete data in a row within a table by using the Jquery contextmenu onclick event. The problem is when i click in a row the last row will be fetched rather than on the selected row.
table:
<table id="ppmpsupplies" class="table table-bordered table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th>Code</th>
<th>General Description</th>
<th>Unit</th>
<th>Quantity</th>
<th>Estimated Budget</th>
<th>Mode of Procurement</th>
</tr>
</thead>
<tbody>
<?php foreach($items as $item){?>
<tr>
<td><?php echo $item->id;?></td>
<td><?php echo $item->description;?></td>
<td><?php echo $item->unit;?></td>
<td><?php echo $item->quantity;?></td>
<td><?php echo $item->budget;?></td>
<td><?php echo $item->mode;?></td>
</tr>
<?php }?>
</tbody>
<tfoot>
<td colspan="3"></td>
<td>Total</td>
<td></td>
</tfoot>
</table>
context menu:
sep3: "----",
"edit": {
name: "Edit",
icon: "fa-pencil-square-o",
callback: function(itemKey, options) {
$('#ppmpsupplies tbody tr').on('click', edit_item(<?php print $item->id ?>));
// var m = "clicked: " + itemKey;
// window.console && console.log(m) || alert(m);
return true;
}
},
sep4: "----",
"delete": {
name: "Delete",
icon: "fa-trash-o",
callback: function(itemKey, options) {
$('#ppmpsupplies tbody tr').on('click', delete_item(<?php print $item->id ?>));
return true;
}
},