2

I am having an issue where in selecting multiple members from a jquery datatable from different pages, If I select 2 members from the first page and 2 from the second page, when I go back the the first page the values check boxes are not ticked and the same when I go back to the second page. Same thing happens while searching through the datatable. What could be the issue? I will post my Controller, Model, View, and Datatable JS below:

VIEW:

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

CONTROLLER:

$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');

MODEL:

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();
}

DATATABLE (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"));
    });

    });

This is pretty much the code I have used, Can somebody please help me with this? Thank you.

5
  • check to google this "datatables mantain checked values throughout pages", a heap of hints pop-up Commented Feb 22, 2016 at 13:46
  • Possible duplicate of jquery datatables selected row's data getting reset on paginated table while navigating on pages Commented Feb 22, 2016 at 13:51
  • this answer has even a jsFiddle: stackoverflow.com/a/29063912/2275490 Commented Feb 22, 2016 at 13:52
  • Thank you Vickel, I will look into these :) Commented Feb 22, 2016 at 16:37
  • Hi Vickel, The values get retained while "bServerSide": false, but it displays only 100 entries out of a possible 2000 entries Commented Feb 23, 2016 at 4:56

1 Answer 1

0

try this one

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

                                    if (this.checked) {
                                        do your code
                                    }

do what you want

                                });
Sign up to request clarification or add additional context in comments.

1 Comment

It should just retain the values on searching as well as going through different pages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.