Php datatable ajax处理中的复选框

Php datatable ajax处理中的复选框,php,jquery,Php,Jquery,我有一个带有ajax处理的datatable。我在每一行都有一个复选框用于多次删除。在顶部还有一个复选框用于一次选中所有复选框。 我需要知道选中的行和未选中的行才能删除 例如,如果我选择我的顶部复选框,它会使用此代码自动将所有复选框更改为选中 $('#select-all').click(function (event) { if (this.checked) { // Iterate each checkbox $(':chec

我有一个带有ajax处理的datatable。我在每一行都有一个复选框用于多次删除。在顶部还有一个复选框用于一次选中所有复选框。 我需要知道选中的行和未选中的行才能删除

例如,如果我选择我的顶部复选框,它会使用此代码自动将所有复选框更改为选中

 $('#select-all').click(function (event) {
        if (this.checked) {
            // Iterate each checkbox
            $(':checkbox').each(function () {
                this.checked = true;
            });
        } else {
            $(':checkbox').each(function () {
                this.checked = false;
            });
        }
    });
但它只对当前页面有效。我有3000多页。我该怎么办

用于服务器端处理的JS

 var dataTable = $('#example2').DataTable({
        processing: true,
        serverSide: true,
        ajax: "?p=online_user_ajax" // json datasource

    });
JSON返回是这样的

$i = 1;
while ($row = mysql_fetch_array($query)) {  // preparing an array
$actions = '<button class="btn btn-small btn-edit" id="edt_user" ></button>';
$checkbox = '<input type="checkbox">';
$nestedData = array();
$nestedData[] = $checkbox;
$nestedData[] = $i;
$nestedData[] = $row["email"];
$nestedData[] = $row["mobile"];
$nestedData[] = $row["first_name"];
$nestedData[] = $row["last_name"];
$nestedData[] = $actions;

$data[] = $nestedData;
$i++;
}
$json_data = array(
"draw" => intval($requestData['draw']), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval($totalData), // total number of records
"recordsFiltered" => intval($totalFiltered), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data   // total data array
);

echo json_encode($json_data);  // send data as json format
$i=1;
而($row=mysql\u fetch\u array($query)){//准备数组
$actions='';
$checkbox='';
$nestedData=array();
$nestedData[]=$checkbox;
$nestedData[]=$i;
$nestedData[]=$row[“email”];
$nestedData[]=$row[“mobile”];
$nestedData[]=$row[“first_name”];
$nestedData[]=$row[“姓氏”];
$nestedData[]=$actions;
$data[]=$nestedData;
$i++;
}
$json_data=array(
“draw”=>intval($requestData['draw']),//对于客户端的每个请求/绘制,他们都会发送一个数字作为参数,当他们收到响应/数据时,他们会首先检查绘制数字,因此我们在draw中发送相同的数字。
“recordsTotal”=>intval($totalData),//记录总数
“recordsFiltered”=>intval($totalFiltered),//搜索后的记录总数,如果没有搜索,则totalFiltered=totalData
“数据”=>$data//总数据数组
);
echo json_encode($json_数据);//以json格式发送数据
为了更好地理解,我添加了两个图像

单击顶部复选框时,复选框处于选中状态

第二页中的复选框未选中


如果您有任何恢复此问题的想法,请提供帮助。

我将注册一个侦听器#selectAll:

$("#selectAll").change(function(){
    if ($(this).is(":checked")) {
        $(".your-class").prop("checked", true);
    }
});
在页面更改时,触发事件

$(".page-change").click(
     $("#selectAll").trigger("change");
)
好的,Sanooj,试试这个: 每当用户单击“下一步”或“上一步”按钮时,请执行以下操作:

$(".page-btn").click(function(){
       $('#selectAll').attr('checked', false);
})
交替

$(".page-btn").click(function(){
       $('#selectAll').prop('checked', false);
})

假设您的下一个和上一个按钮有一个公共类页面btn,它将检测您的单击并取消选中顶部复选框,该复选框不会在加载下一个/上一个页面数据时更新。每当加载新页面数据时,您需要更新该复选框。

最后,我通过将顶部复选框值发送到服务器端解决了这个问题

$checkbox='<input type="checkbox">';
if (!empty($requestData['columns']['checkbox']['search']['value'])) {
    $checkbox='<input type="checkbox" checked>';
} 
$nestedData = array();
$nestedData[] = $checkbox;
$nestedData[] = $i;
$nestedData[] = $row["email"];
$nestedData[] = $row["mobile"];
$nestedData[] = $row["first_name"];
$nestedData[] = $row["last_name"];
$nestedData[] = $actions;
$checkbox='';
如果(!empty($requestData['columns']['checkbox']['search']['value'])){
$checkbox='';
} 
$nestedData=array();
$nestedData[]=$checkbox;
$nestedData[]=$i;
$nestedData[]=$row[“email”];
$nestedData[]=$row[“mobile”];
$nestedData[]=$row[“first_name”];
$nestedData[]=$row[“姓氏”];
$nestedData[]=$actions;

因此,如果选中顶部复选框,所有其他复选框都将被选中

您是否使用ajax分页?是的,这是带有ajax的服务器端数据(一次仅显示10行)。实际上,分页ajax是我的问题,即当您转到下一页时,页面是否会重新加载?否,它不会重新加载