10

iCheck works with datatables only on the first page. When I navigate to any other page it shows checkboxes but they don't have iCheck applied. This code helps but doesnt' work 100%.

function turn_on_icheck(checkboxClass)
{
    $('input[type=checkbox]').iCheck({
        checkboxClass: checkboxClass
    });
}
$('.data-table').on('page', function() {
    turn_on_icheck();
});

When I go to the 2nd page it shows everything fine now, but if I go back to the page that was previously visited, the checkboxes are not there. It seems to me like it causes an error because there is already an instance of iCheck running there. Is there any way to check if there is one running or not?

5 Answers 5

13

I had the same issue with asp.net grid. Please use the on draw.dt event, that will help in paging and display menu as well

$('.data-table').on('draw.dt', function () {
    turn_on_icheck();
});
3
  • 1
    Glad it helped :) @reformed
    – hsobhy
    Commented Jul 4, 2016 at 19:49
  • Have you had any issues with having callbacks not working such as on('isChecked') when on another page, assuming you are using pagination? Commented Dec 27, 2016 at 19:04
  • I don't remember that I had issues with that but some times - with ASP.NET update panels - had to recall the things again like in that fiddle jsfiddle.net/sonr2aje
    – hsobhy
    Commented Dec 28, 2016 at 19:51
2

Here is a simpler way to do this:

$('.inputClass').iCheck({
        handle: 'checkbox',
        checkboxClass: 'icheckbox_flat-blue'
    });

source Good Luck

1

When datatables refresh the values, new inputs are render and the inputs need to apply again the icheck funtion.

$(document).ajaxComplete(function() {
    $('input[type=checkbox]').iCheck({
        checkboxClass: checkboxClass
    });
});
3
  • Please add some explanation on how this solves the issue
    – Huangism
    Commented Feb 12, 2015 at 18:18
  • When datatables refresh the values, new inputs are render and the inputs need to apply again the icheck funtion.
    – platix
    Commented Feb 24, 2015 at 13:53
  • 1
    You can edit the question and add it the explanation
    – Huangism
    Commented Feb 24, 2015 at 14:27
1

Do this (write your code in "drawCallback" function):

...
'drawCallback': function(settings) {
     $('.i-checks').iCheck({
         checkboxClass: 'icheckbox_square-green'
     });
 },
 ...

It solved my problem.

0

this is how i solved it... you should give the icheck some time until it finishes before calling the DataTable function... use the JQUERY's when function

function Typer(callback)
{    
    if ($("input.flat")[0]) 
    {
        $('input.flat').iCheck({
            checkboxClass: 'icheckbox_flat-green',
            radioClass: 'iradio_flat-green'
        });
    }
}


function enableDataTableMain()
    {
    var table = $('#tableWithData').DataTable({
     "aoColumnDefs": [
        {
            'bSortable': false,
            'aTargets': [0]
        } //disables sorting for column one
    ],
    "tableTools": {
        "sSwfPath": "swf/copy_csv_xls_pdf.swf"
    }});                    
    var tt = new $.fn.dataTable.TableTools( table );
    $( tt.fnContainer() ).insertBefore('div.functionDiv');
}


    $(document).ready(function() {
    $.when( Typer() ).done(function() {
       enableDataTableMain();
    });
});

Not the answer you're looking for? Browse other questions tagged or ask your own question.