The bStateSave option can be used to save the state of the DataTable in a cookie.
I'd like to clean this cookie when logging out.
Currently, I checked the name of the cookie from my browser and changed its expiration date with PHP setcookie() at logout, coding the name in hard. It works, but it's a bit ugly since I don't know how to retrieve the cookie name from API.
Is there a proper way to do this?
Thanks
I don't know if you already got an answer, but this is what I used.
there is a property to initialize DataTables called: iCookieDuration. What you should do is to set a time expressed in seconds of "cookie duration"
then you have:
$('.datatable').dataTable({
"iCookieDuration": 60*60*24,// 1 day (in seconds)
});
then you set a time that you consider optimal. hope to help you !!
State saving in DataTables is done by saving a JSON string to a cookie, allowing it to maintain as much browser compatibility as possible, while keeping the state storage on the client-side. At times it can be useful to be able to modify the parameters that are saved by the table.
If you want to clear datatable state on logging-out then i would like to suggest to simply clear storage.
The removeItem()
method of the Storage interface, when passed a key name, will remove that key from the storage.
function populateStorage() {
localStorage.setItem('bgcolor', 'red');
localStorage.setItem('font', 'Helvetica');
localStorage.setItem('image', 'myCat.png');
localStorage.removeItem('image');
}
OR
Just write in javascript at loggin-out action.
echo '<script type="text/javascript">localStorage.clear();</script>';
ie
<script type="text/javascript">localStorage.clear();</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With