I have used checkbox in all rows, such that when each checkbox will be checked I will get the Id's of them, everything is working fine with what I have implemented but the issue is that I only get the checked Id's of the particular page of datatable. Means If I checked the checkbox of one data in page 1 and also checked the checkbox of the other data in page 2, then when I submit I got only the data of page 2. What do I want is that I should get the Id's of data from page1, page2, page3 and so on.
This is where all my data's are coming
@foreach($data as $key => $question_bank)
<tr id="{{ $question_bank->id }}">
<td>
<input type="checkbox" data-id="{{ $question_bank->id }}" class="add_check">
</td>
<td>{{++$i}}</td>
<td>{{ $question_bank->questionCategory->category }}</td>
<td>{{$question_bank->question}}</td>
</tr>
@endforeach
<button type="submit" id="add_to" class="mt-3 btn btn-primary float-right">Add</button>
This is my jquery part
$(document).on('click','#add_to',function(e){
e.preventDefault();
var questionids_arr = [];
$("input:checkbox[class=add_check]:checked").each(function () {
questionids_arr.push($(this).attr('data-id'));
});
console.log(questionids_arr);
return false;
});