我遇到一个问题,即从不同页面的jquery数据表中选择多个成员时,如果我从第一页中选择2个成员,从第二页中选择2个成员,则当我返回第一页时,值复选框未选中并且回到第二页时也是如此。搜索数据表时也会发生相同的情况。可能是什么问题?我将在下面发布我的Controller,Model,View和Datatable 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

                                });

关于javascript - Codeigniter-jQuery Datatables在搜索和分页时不会保留复选框中的选中值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35549890/

10-10 23:35