I am trying to get the checked row data but I got no idea how can I pass it from on submit function. So I can pass the data to another php
datatable
and how I can retrieve the data once I pass it over?
$('#submit_form').on('submit', function(){
//function to get the checkbox that is checked data and pass it to another php
});
My html table
<form id="submit_form" action="<?php echo site_url('Test_product/import');?>">
<p align="right"><button name="import" type="submit" form="submit_form">Import </button></p>
<table id="import" width="100%">
<thead>
<tr>
<th><input name="select" id="select" type="checkbox" checked></th>
<th></th>
<th>Name</th>
<th>SKU</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th></th>
<th>Name</th>
<th>SKU</th>
</tr>
</tfoot>
</table>
</form>
My ajax
<script>
$(document).ready(function() {
var table = $('#import').DataTable({
bProcessing: true,
ajax: "localhost/product.php",
columns: [
{
data: 'id',
searchable: false,
orderable: false,
className: 'dt-body-center',
render: function (data, type, full, meta){
return '<input type="checkbox" name="' +data+ '"'+ 'checked>'; }
},
{data: 'photo'},
{data: 'name'},
{data: 'sku'}
]
});
$('#select').on('click', function(){
// Get all rows with search applied
var rows = table.rows({ 'search': 'applied' }).nodes();
// Check/uncheck checkboxes for all rows in the table
$('input[type="checkbox"]', rows).prop('checked', this.checked);
});
$('#submit_form').on('submit', function(){
var data = table.rows(this).data();
alert(data[0]);
});
});
</script>
My json output
{"data":[{"id":35,"name":"_testing_product_009","sku":"-","photo":""}]}