I am using a few custom jquery buttons with datatables to do some sorting. Unfortunately when I leave the page and come back, datatables remembers its state, but the toggle button doesnt. So I am trying to set a cookie when the button is toggled so I can read it later, but I cant seem to get it working.
Here is my button code with the cookie creation:
$('#completed_button').bind('change', function(){
if($(this).is(':checked')){
$(this).button('option', 'label', 'Hide Completed');
oTable.fnFilter('Completed',6,false);
$.cookie('showCompletedState', 'checked');
} else {
$(this).button('option', 'label', 'Show Completed');
oTable.fnFilter('',6,false);
$.cookie('showCompletedState', 'unchecked');
}
});
Now here is my attempt at reading the cookie and setting the button state:
var showCompletedState = $.cookie('showCompletedState');
if (showCompletedState == 'checked') {
<-- need something here to actually change button state -->
$('#completed_button').button('option', 'label', 'Hide Completed');
oTable.fnFilter('Completed',6,false);
} else if (showCompletedState == 'unchecked') {
<-- need something here to actually change button state -->
$('#completed_button').button('option', 'label', 'Show Completed');
oTable.fnFilter('',6,false);
}
As per Dave’s suggestion, answer turned out to be
$("#completed_button").prop("checked", true);