Pass data-id into Controller after multiple select
Pass data-id into Controller after multiple select
I have tried like this to pass that data-id but does not works
Kindly assist me
<script type="text/javascript">
$(document).ready( function () {
var table = $('#example').DataTable({
columnDefs: [{
orderable: false,
className: 'select-checkbox',
targets: 0
}],
select: {
style: 'os',
selector: 'td:first-child'
},
order: [[1,'asc']]
});
$('#example').on('click', '#select_all', function() {
if ($('#select_all:checked').val() === 'on') {
table.rows().select();
}
else {
table.rows().deselect();
}
});
} );
$('#example tbody').on('click','.received-all', function(e) {
var idsArr = [];
$(".checkbox:checked").each(function() {
idsArr.push($(this).attr('data-id'));
});
if(idsArr.length <=0)
{
alert("Tafadhali, Chagua Device Hata Moja.");
} else {
if(confirm("Je,Unataka Kurudisha Device Zote ?")){
var dataIDs = idsArr.join(",");
alert(dataIDs);
$.ajax({
url:"{{route('returnUnits.border')}}",
type:'POST',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data:{ids:dataIDs},
success: function (data) {
alert('Device Zote Zimetumwa, Asante');
location.reload();
// console.log(data);
},
error: function (data) {
alert(data.responseText);
}
});
}
}
});
My html code
<a href="#" id="received-all" class="btn btn-sm btn-warning pull-right received-all"> <span class="glyphicon glyphicon-" aria-hidden="true"></span>SUBMIT</a>
<table id="example" class="display " width="100%">
<thead>
<tr>
<th>Select All<input type="checkbox" id="select_all"></th>
<tbody>
@foreach($data as $key=>$dt)
<tr>
<td ><input type="hidden" data-id="{{$dt->UntagNumber}}" class="checkbox"></td>
<td>{{++$key}}</td>
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
In what way doesn't it work? We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
@colin the problem here is how can i taken that
data-id
and pass to my controller?right now i can able to check all but when i click my button
submit
, does not takesdata-id
To progress this, please provide a test case as requested,
Colin