Initialise the toggles plugin dynamically, so you also "toggles" elements injected when changing page, sorting etc :
jQuery('#example').on('draw.dt', function() {
jQuery('.toggle').each(function() {
$(this).toggles({
on: $(this).data('toggle-on')
});
});
});
You must also use a delegated event handler. As it is now, you only have a click-handler for the toggles on the first page :
$('#example').on('click', '.toggle', function () {
console.log($(this).data('toggle-on'));
if ($(this).data('toggle-on') == true) {
$(this).data('toggle-on', false)
console.log('Turning off ' + $(this).data('contact-id'));
} else {
$(this).data('toggle-on', true)
console.log('Turning on ' + $(this).data('contact-id'));
}
});
demo -> http://jsfiddle.net/gmptpbqg/ where all .toggle
elements become "toggled" and on / off state is remembered correctly across the pages.