[英]Datatable jquery to limit number of selectable rows to maximum of 5 on checkbox select
I am using datatables example: https://datatables.net/extensions/select/examples/initialisation/checkbox.html to select multiple rows using checkboxes.我正在使用数据表示例: https ://datatables.net/extensions/select/examples/initialisation/checkbox.html 使用复选框选择多行。 This is working fine.
这工作正常。 I can select multiple rows holding the Ctrl key.
我可以按住 Ctrl 键选择多行。 The bottom of the table displays the number of rows selected.
表格底部显示选定的行数。 The issue I am having is I want to stop the user from selecting more than 5 rows.
我遇到的问题是我想阻止用户选择超过 5 行。 How can I tweak the JQUERY to limit to maximum 5 rows selected and then it prevents the user from selecting anymore unless they de-select a row?
如何调整 JQUERY 以限制最多选择 5 行,然后阻止用户再选择,除非他们取消选择行?
var table = $('#tabledt').DataTable({
columnDefs: [{
orderable: false,
className: 'select-checkbox',
targets: 0
}],
select: {
style: 'os',
selector: 'td:first-child'
},
order: [[1, 'asc']]
});
table.on('select', function (e, dt, type, ix) {
var selected = dt.rows({ selected: true });
if (selected.count() > 5) {
dt.rows(ix).deselect();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.