0

I'm using the metronic theme datatable and i want to get selected checkboxes values. This is the manage datatables from the metronic theme.

<table class="table table-striped table-bordered table-hover table-checkable order-column" id="sample_1">
  <thead>
     <tr>
      <th></th>
      <th class="text-center"> User Name</th>
      <th class="text-center">Mobile</th>
      <th class="text-center">Email</th>
     </tr>
 </thead>
      @foreach($requests as $request)
         <tr class="odd gradeX text-center ">
           <td>
             <label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
                 <input type="checkbox" class="checkboxes" value="{{$request->id}}" />
                   <span></span>
             </label>
           </td>
           <td>{{$request->name}}</td>
           <td>{{$request->mobile}}</td>
           <td>{{$request->email}}</td>
        </tr>
     @endforeach
2
  • you want to solve it using jquery then a selector $("input:checked") will give you all checboxes that are checked Commented Jun 3, 2018 at 9:22
  • How did it go? @Arslan Akram Commented Jun 5, 2018 at 6:07

2 Answers 2

1

This solved my problem.

   var checkbox_value = [];
    var oTable = $('#sample_1').dataTable();
    var rowcollection =  oTable.$(".call-checkbox:checked", {"page": "all"});
    rowcollection.each(function(index,elem){
        checkbox_value.push($(elem).val());
    });
Sign up to request clarification or add additional context in comments.

Comments

0

Since you have jQuery in your tags, I am assuming that you can do this by the use of jQuery? In case of jQuery:

You can use the :checked selector to target your checked radio button. In your case, you have a class to go by, so it will look something like:

$(".checkboxes:checked").val();

This will give you the value of the checked checkbox. You can also check to see if a certain checkbox is checked and return a boolean value by using .is(":checked"). That will return true/false depending on whether the checkbox is checked or not, and then you can construct a logic from that.

You can also make a checkbox be checked by using either:

$(".checkboxes").attr('checked', true);

or,

$(".checkboxes").prop('checked');

Note that I am using your .checkboxes class, since that's what you have to target in your example. Note that a class is usually something you will have repeated instances of (not in your example, but generally speaking). So these examples will target all instances having that class. If you want to target a specific element, use id instead, i.e $("#....").

Hope this helped. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.