Pass data-id into Controller after multiple select

Pass data-id into Controller after multiple select

MelxMelx Posts: 3Questions: 1Answers: 0
edited September 2021 in General

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.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • MelxMelx Posts: 3Questions: 1Answers: 0

    @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 takes data-id

  • MelxMelx Posts: 3Questions: 1Answers: 0

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    To progress this, please provide a test case as requested,

    Colin

Sign In or Register to comment.