如何获取不同分页页面PHP和javascript的DataTable中复选框的选定值? [英] How to get selected values of checkboxes in DataTable of different pagination pages PHP and javascript?

查看:89
本文介绍了如何获取不同分页页面PHP和javascript的DataTable中复选框的选定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个dataTable来显示数据库中的所有记录,并为该表中的每一行提供一个复选框。我的桌子有多页。问题是我只能获取当前页面的复选框值,因为系统只能看到可见的复选框。我想从不同页面获取特定的检查值或所有检查的值,并将它们推到数组中。我该如何实现?我只能在数据表atm中获取当前所选页面的检查值。我已经搜索并尝试了类似问题

Basically I have a dataTable that displays all the records from the database, and a checkbox for each row within the table. My table has multiple pages. The problem was that I can only get the checkbox values of the current page selected because the system can only see checkboxes that are visible. I want to get specific checked values or all checked values from different pages and push them to the array. How can I achieve this? I can only get the checked value of current selected page in datatable atm. I have searched and tried similar problem, but it's still not working.

下面是我的代码

显示复选框的PHP代码

PHP code to display checkboxes

foreach($stmt as $row){echo "<tr><td>"."<input type='checkbox' name='check_list' id='checklist' value='$row['id']' style='width:20px; height: 20px'/>"}   

JavaScript代码

Javascript code

function getCheckboxVals(){

    var check = $('input[name="check_list"]:checked').length;
    var mycheckboxes = new Array();

    //IF NO CHECKBOX CHECKS
    if(check == 0){
        eModal.alert('PLEASE SELECT ISSUES BEFORE YOU EXPORT CONTENTS!!!');
        return false;
    }

    //IF ONE OR MORE CHECKBOXES CHECK
    if(check == 1){
        $('input[name="check_list"]:checked', table.fnGetNodes()).serialize().each(function(){

        mycheckboxes.push(this.value);

    });
}else{
    $('input[name="check_list"]:checked').each(function(){

        mycheckboxes.push(this.value);

    });
}

}

推荐答案

只能获取当前页面上复选框的值的问题是由于使用DOM方法或查询而没有直接使用DataTables的API。为了提高效率,DataTable仅将值存储在当前页面上。为了访问其他值,您必须使用以下方式访问表:

The issue with only being able to get the values of the check boxes on the current page comes from the use of DOM methods or querying without using the DataTables' API directly. For efficiency, the DataTable only stores the values on the current page. In order to access other values you must use access the table using:

dataTable.rows().nodes().to$().find('input[type="checkbox"]').each(function(){}

此例中的数据表是您定义的数据表。

The datatable in this instance being your defined datatable.

此外,此处是正在存储并发送到服务器的复选框值的有效版本

Additionally, here is a working version of checkbox values being stored and sent to the server

有关更多信息,请参见数据表常见问题解答和有关DOM的主题。

For more info see the DataTable FAQs and topics on DOM.

这篇关于如何获取不同分页页面PHP和javascript的DataTable中复选框的选定值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆