Can not save StateDatatable after restart

Can not save StateDatatable after restart

olalaolala Posts: 7Questions: 3Answers: 1

I want save the position of column that user have reordered in DataTable and this is my code:
tbl= $("#tblMain").dataTable({
"bDestroy": true,
"sDom": 'C<"clear">Rlfrtip',
"oColVis": {
"buttonText": "Show/Hide"
},
"bStateSave": true,
"bAutoWidth": false,
"iCookieDuration": 60 * 60 * 24 * 365,
"bFilter": true,
"iPageLength": 50,
"oSearch": { "bSmart": false },
"fnInitComplete": CompleteInitDatatable,
"fnStateSave": SaveStateDatatable,
"fnStateLoad": LoadStateDatatable
});

.js file

var accName = localStorage.getItem("accName_" + window.location.hostname);
function SaveStateDatatable(oSetting, oData) {
localStorage.setItem(accName + "" + oSetting.nTable.id + "" + window.location.href, JSON.stringify(oData));
}

function LoadStateDatatable(oSetting) {
var jsonData = JSON.parse(localStorage.getItem(accName + "" + oSetting.nTable.id + "" + window.location.href));
if (jsonData) {
$(jsonData.aoSearchCols).each(function (index, item) {
item.sSearch = "";
});
}
return jsonData;
}

function CompleteInitDatatable(oSetting, json) {
$('#' + oSetting.nTable.id + ' tfoot tr').appendTo('#' + oSetting.nTable.id + ' thead');
}

when I restart web browser (google chrome) or log out account, it still save state datatable, but when I restart my computer, the state lost.

plz help me

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    why are you making your keys so complicated? Simplify since it is being saved and pulled from the same client machine.

  • olalaolala Posts: 7Questions: 3Answers: 1

    i dont think it is problem, i need that key because maybe have many account login on one computer

This discussion has been closed.