代码点火器 - jQuery 数据表 搜索和分页时不会保留复选框中的选中值


Codeigniter - jQuery Datatables Checked values from check boxes are not retained while searching and paginating

我遇到了一个问题,即从不同页面的 jquery 数据表中选择多个成员,如果我从第一页选择 2 个成员,从第二页选择 2 个成员,当我返回第一页时,值复选框没有被选中,当我返回第二页时也是如此。搜索数据表时也会发生同样的事情。可能是什么问题?我将在下面发布我的控制器、模型、视图和数据表 JS:

视图:

<div  class="col-md-12"><?php echo $this->table->generate(); ?></div>

控制器:

$tmpl = array ( 'table_open'  => '<table id="big_table" border="1" cellpadding="2" cellspacing="1" class="table table-striped">' );
$this->table->set_template($tmpl); 
$this->table->set_heading('<input type="checkbox" id="selAll" name="select_all" />','Customer Name','Email','Phone');

型:

public function list_customers($center_id ='',$course_id =''){
$this->datatables->select("customer_id, CONCAT_WS( ' ' ,  firstname , lastname ) as firstname, email ,phone")->where('is_disable',0)
    ->edit_column('customer_id', input_checkbox('customer_id[]' ,'$1' ),'customer_id')->from($this->_table_name);
if(!empty($center_id)) $this->db->where('category',$center_id);
    if(!empty($course_id)){
        $this->db->where('customer_id IN (select customer_id from `dance_customer_course`  WHERE dance_customer_course.`festival_id` = '.$course_id.')');
    } 
    return $this->datatables->generate();
}

数据表 (JS):

<script type="text/javascript">

    $(document).ready(function() {
        $("#sform").submit(function(){
            if($('.checkbox:checked').length < 1){
                alert("Please select the customer");
                return false
            }
            if($('#content').val() == ''){
                alert("Please enter content");
                return false
            }
        });
    var oTable = $('#big_table').dataTable( {
        "bProcessing": true,
        "bInfo": false,
        "bServerSide": true,
        "sAjaxSource": '<?php echo base_url(); ?>sendsms/list_customers',
                "bJQueryUI": true,
                "sPaginationType": "full_numbers",
                "iDisplayStart ":20,
                "oLanguage": {
            "sProcessing": "<img src='<?php echo base_url(); ?>img/ajax-loader.gif'>"
        },  
        "fnInitComplete": function() {
                //oTable.fnAdjustColumnSizing();
         },
                'fnServerData': function(sSource, aoData, fnCallback)
            {
              $.ajax
              ({
                'dataType': 'json',
                'type'    : 'POST',
                'url'     : sSource,
                'data'    : aoData,
                'success' : fnCallback
              });
            }
        });


    $('#selAll').click(function(e){
        if (e.stopPropagation) e.stopPropagation();
        var checkBoxes = $(".checkbox");
        if(checkBoxes.prop("checked")) $(this).text("Check All");
        else $(this).text("Uncheck All");
        checkBoxes.prop("checked", !checkBoxes.prop("checked"));
    });
    });

这几乎是我使用的代码,有人可以帮我吗?谢谢。

试试这个

 $('input[type=checkbox]').each(function () {
                                    newvalue = ( $(this).val());
                                    if (this.checked) {
                                        do your code
                                    }
do what you want
                                });