复选框仅适用于 jQuery 数据表中的当前分页页面

Checkboxes will only work on current pagination page in jQuery datatables

我正在使用 jquery 数据 table 列出我的内容,这些内容具有复选框选择和选定内容 post 数据,但在提交的表单中仅发送当前页面数据。

我的数据table代码是:

$('#select').dataTable( {
        "order": [[ 2, "desc" ]],
        "lengthMenu": [[50, -1], [50, "All"]],
        "columnDefs": [
                { orderable: false, targets: [0, 1, 3, 5] },
                { "width": "20px", "targets": [0, 1] },
                { "width": "80px", "targets": [5] }
        ],

});

当我点击提交时,它只提交当前页面值的复选框数组。

我已经提到这个 link 已经 Pagination with selected check boxes. Checkboxes will only work on current pagination page. jQuery datatables 但是那里提供的 link 和 link 的解决方案不起作用。

您可以使用以下代码获取所有选中的复选框值这可能对您有所帮助

var myArray = [];
var id = "";
var oTable = $("#example").dataTable();
$(".class1:checked", oTable.fnGetNodes()).each(function() {
    if (id != "") {
        id = id + "," + $(this).val();
    } else {
        id = $(this).val();
    }
});

最后可以查看。

var table = $("#yourtablename").DataTable({
    //your datatable options(optional)
});

现在jQuery可以通过以下代码访问所有行

  table.$('td > input:checkbox').each(function () {
            // If checkbox is checked
            if (this.checked) {
             //Your code for example
                alert($(this).attr('name'));
            }
    });