从复选框中的数据表中删除排序
Remove sorting from Datatable in checkboxes
每当我点击 select-all on the top of the table 时,它会返回到第一页。我需要 select table 中的一些行并将它们导出到 CSV 文件但是当 select 在不同的页面上时,当我单击 select 时它会返回到第 1 页。
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_<?php echo $valuep['0'] ;?>">
<input id="checkbox_<?php echo $valuep['0'] ;?>" type="checkbox" name="leads_ids" value="<?php echo $valuep['0'] ;?>" class="select_click">
<span></span>
</label>
<input type="hidden" id="enable_all" name="enable_all" value="1">
<input type="hidden" id="lead_contact_id_<?php echo $valuep['0'] ;?>" name="contact_id" value="<?php echo $valuep['0'] ;?>">
</div>
<span id="custom_controls"></span>
</td>
var table = $('#mytable').DataTable({
'columnDefs': [{
'targets': 0,
'searchable': false,
'orderable': false,
'className': 'checkbox check-success'
}],
'order': [
[1, 'asc']
]
});
I suggest try trigger click all checkbox in the current visible page.
var myTable = $('#mytable').DataTable({
'columnDefs': [{
'targets': 0,
'searchable': false,
'orderable': false,
}],
'order': [
[1, 'asc']
],
});
$(document).on('click', '#select_all', function() {
$('input.select_click', document).each(function() {
$(this).trigger('click');
});
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/1.11.3/css/dataTables.bootstrap4.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/dataTables.bootstrap4.min.js"></script>
<table class="table table-bordered" id="mytable">
<thead>
<th><a href="#" id="select_all">Select All</a></th>
<th>Data</th>
</thead>
<tbody>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_1" type="checkbox" name="leads_ids" value="1" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 1</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
</tbody>
</table>
每当我点击 select-all on the top of the table 时,它会返回到第一页。我需要 select table 中的一些行并将它们导出到 CSV 文件但是当 select 在不同的页面上时,当我单击 select 时它会返回到第 1 页。
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_<?php echo $valuep['0'] ;?>">
<input id="checkbox_<?php echo $valuep['0'] ;?>" type="checkbox" name="leads_ids" value="<?php echo $valuep['0'] ;?>" class="select_click">
<span></span>
</label>
<input type="hidden" id="enable_all" name="enable_all" value="1">
<input type="hidden" id="lead_contact_id_<?php echo $valuep['0'] ;?>" name="contact_id" value="<?php echo $valuep['0'] ;?>">
</div>
<span id="custom_controls"></span>
</td>
var table = $('#mytable').DataTable({
'columnDefs': [{
'targets': 0,
'searchable': false,
'orderable': false,
'className': 'checkbox check-success'
}],
'order': [
[1, 'asc']
]
});
I suggest try trigger click all checkbox in the current visible page.
var myTable = $('#mytable').DataTable({
'columnDefs': [{
'targets': 0,
'searchable': false,
'orderable': false,
}],
'order': [
[1, 'asc']
],
});
$(document).on('click', '#select_all', function() {
$('input.select_click', document).each(function() {
$(this).trigger('click');
});
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/1.11.3/css/dataTables.bootstrap4.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/dataTables.bootstrap4.min.js"></script>
<table class="table table-bordered" id="mytable">
<thead>
<th><a href="#" id="select_all">Select All</a></th>
<th>Data</th>
</thead>
<tbody>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_1" type="checkbox" name="leads_ids" value="1" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 1</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
<tr>
<td class="check_box_data">
<div class="checkbox check-success">
<label class=" mt-checkbox mt-checkbox-outline" for="checkbox_1">
<input id="checkbox_2" type="checkbox" name="leads_ids" value="2" class="select_click">
<span></span>
</label>
</div>
<span id="custom_controls"></span>
</td>
<td>Test Data 2</td>
</tr>
</tbody>
</table>