Add the ability to select rows in a jQuery DataTable
To add the ability to select rows in a jQuery DataTable, you can use the select option provided by the DataTables library.
Here's an example of how to add row selection to a DataTable:
$('#myTable').DataTable({ select: true });
This will enable row selection for the table with the ID myTable. Once you've added row selection, you can access the selected rows using the rows({selected:true}) method:
var selectedRows = $('#myTable').DataTable().rows({selected:true}).data();
This will return an array of data objects for the selected rows.
You can also handle the select event to perform custom actions when a row is selected:
$('#myTable').on('select.dt', function(e, dt, type, indexes) { var selectedRows = dt.rows({selected:true}).data(); // do something with the selected rows });
Komentar
Posting Komentar