state.clear() is not working
state.clear() is not working
I am using datatables.net version 1.10.4.
I am trying to clear state on page load event. Here is my code on which I am trying to clear state, but it is not working. Can anyone help to resolve this?
var invoiceTable = $('#invoiceDetails').dataTable({
"paging": true,
"stateSave": true, //to save pagination state
"ordering": true,
//"iCookieDuration": 1,
"info": false,
"searching": false,
"lengthChange": false,
"pageLength": 5,
"columnDefs": [
{
"targets": [0, 10],
"orderable": false
}
]
});
var datable = $('#invoiceDetails').DataTable();
datable .state.clear();
This question has an accepted answers - jump to answer
Answers
Problem there is that the table has already loaded the saved state. If you don't want it to load the saved state, remove the
stateSave: true
.Allan
Thank you allan for your answer.
I want to save state but when page is gets reload, it should be remove save state.
I want to keep save state true because I have drop down in my last column and when user click on it, it is opening modal pop up & user save data. once modal pop up gets close, datatable state should be saved & user needs to stay on that table page(say page number 3 in table pagination).
I want to remove save state when page reload or user will go to some page and comes back to same page, state should be clear.
If the modal is a Javascript widget, then you presumably aren't destroying the table and therefore it will already still be on page 3 (for example)? As such you wouldn't need state saving.
Allan
Hi Allan,
I found the solution. I did following steps.
var table = $('#invoiceDetails').DataTable();
table.state.clear();
table.destroy();
$('#invoiceDetails').dataTable({
"paging": true,
"stateSave": true, //to save pagination state
"ordering": true,
//"iCookieDuration": 1,
"info": false,
"searching": false,
"lengthChange": false,
"pageLength": 5,
"columnDefs": [
{
"targets": [0, 10],
"orderable": false
}
]
});
Once again thank you for your help.