I needed to clear the persistence state when the session ended. I created a simple custom state writer and reader that wrote and read data from sessionStorage instead of localStorage. I was inspired by this documentation.
Here is the code:
const pageTable = new Tabulator("#pagelist-table", {
pagination:true, //enable pagination
paginationMode:"local", //enable local pagination
paginationSize:pageSize, //optional parameter to request a certain number of rows per page
persistence:{
sort: true, //persist column sorting
filter: true, //persist filters
headerFilter: true, //persist header filters
group: false, //persist row grouping
page: true, //persist page
columns: false, //persist columns
},
persistenceWriterFunc:function(id, type, data){
//id - tables persistence id
//type - type of data being persisted ("sort", "filter", "group", "page" or "columns")
//data - array or object of data
sessionStorage.setItem(id + "-" + type, JSON.stringify(data));
},
persistenceReaderFunc:function(id, type){
//id - tables persistence id
//type - type of data being persisted ("sort", "filter", "group", "page" or "columns")
var data = sessionStorage.getItem(id + "-" + type);
return data ? JSON.parse(data) : false;
},
/* The rest of the configuration continues from here */
}
You can see the full working code here.