Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTables + iCheck + pagination

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?

like image 392
user1029829 Avatar asked Feb 07 '14 20:02

user1029829


1 Answers

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

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

It solved my problem.

like image 111
Ganj Khani Avatar answered Sep 22 '22 09:09

Ganj Khani