【问题标题】:Codeigniter - jQuery Datatables Checked values from check boxes are not retained while searching and paginatingCodeigniter - jQuery Datatables 在搜索和分页时不会保留来自复选框的选中值
【发布时间】:2016-06-03 15:47:27
【问题描述】:

我在从不同页面的 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"));
    });

    });

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

【问题讨论】:

标签: javascript php jquery codeigniter datatable


【解决方案1】:

试试这个

 $('input[type=checkbox]').each(function () {
                                    newvalue = ( $(this).val());

                                    if (this.checked) {
                                        do your code
                                    }

do what you want

                                });

【讨论】:

  • 它应该只保留搜索和浏览不同页面的值
猜你喜欢
  • 2017-01-27
  • 2021-01-10
  • 2015-12-27
  • 2012-04-23
  • 1970-01-01
  • 1970-01-01
  • 2012-03-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多