Clear bStateSave cookie

The bStateSave parameter can be used to save the DataTable state in a cookie.

I want to clear this cookie on logout.

Currently, I checked the cookie name from my browser and changed its expiration date to PHP setcookie () when I logged out, with a hard-coded name. It works, but it's a little ugly, since I don't know how to get the cookie name from the API.

Is there any way to do this?

thanks

+4
source share
3 answers

I do not know if you have an answer, but that is what I used.

There is a property to initialize DataTables called iCookieDuration. What you have to do is set the time, expressed in seconds, to “cookie duration”

then you have:

$('.datatable').dataTable({ "iCookieDuration": 60*60*24,// 1 day (in seconds) }); 

then you set the time that you think is optimal. hope to help you!

+6
source

The only thing I can think of is this:

fnCookieCallback from http://datatables.net/ref

You could cancel the cookie to set the expiration time and save it. I don’t know if this will help, but I hope you find the answer :)

0
source

Saving state in DataTables is done by storing the JSON string in a cookie, allowing it to maintain as much compatibility with the browser as possible while maintaining the state store on the client side. From time to time, it may be useful to change the settings stored in the table.

If you want to clear the state of the data when you log in, I would suggest simply clearing the storage.

The removeItem() method of the storage interface, when passing the key name, will remove this 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 with loggin-out action.

 echo '<script type="text/javascript">localStorage.clear();</script>'; 

t

 <script type="text/javascript">localStorage.clear();</script> 
0
source

All Articles