我有下一个数据表
HTML
<table id="example" class="row-border hover">
<thead>
<tr>
<th>ID</th>
<th>Iden.</th>
<th>Nombres</th>
<th>Sel.</th>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Iden.</th>
<th>Nombres</th>
<th>Sel.</th>
</tr>
</tfoot>
</table>
JS
$('#example').DataTable({
scrollX: true,
deferRender: true,
"aaData": data.Data,
"columns": [{ data: "ID" },
{ data: "Identificacion" },
{ data: "Nombres" },
{ "data" : null,
"targets" : -1,
"orderable" : false,
"className" : "all",
"width" : "20px",
"render" : function(data, type, full) {
let texto = "";
texto = '<input type="checkbox" id="check_test" value="' + data.ID + '" />';
return texto;
}
}
]
});
我想获取所选复选框的值,所以我尝试了这个
var aux = [];
aux = $('#example tbody input[type=checkbox]:checked').map(function(_, el) {
return $(el).val();
}).get();
但是,这仅获取从分页数据表的活动页面中选择的值
如何获取所有数据页面上选定复选框的值?
使用$()
DataTables API 方法从所有页面检索数据,而不仅仅是第一页。
例如:
var $checkboxes = $('#example').DataTable().$('input[type=checkbox]:checked');
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句