I am using jquery plugin Datatables to manipulate my rows Actually it has a tabletools plugin that allow checkall function, however, I can check all the items/ check multi, but how can add a delete button and return the row selected?
I already have the sql query for deletion and the function for a deletion warning popup box .
Thank you
Select all in datatable
Document on how to retrieve row, but i still don't understand how to do this, thank you
$(document).ready( function () {
$('#viewSub').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "../plugin/DataTables-1.9.0/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf",
"sRowSelect": "multi",
"aButtons": [
"select_all",
"select_none",
"copy",
"print",
"delete", <===********can not add here, seems only allow pre-defined button.
{
"sExtends": "collection",
"sButtonText": "Save",
"aButtons": [ "csv", "xls", "pdf" ]
}
]
}
} );
} );
You can add a function to catch selected row:
$(document).ready( function () {
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"fnRowSelected": function ( node ) {
alert( 'The row with ID '+node.id'+ was selected' );
}
}
} );
} );
In this function, you can, for example, add set value of a hidden field to node.id
, a a simple <button>Delete</button>
and onClick
handler to this button to delete row with selected id.
Check also answers to this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With