@@ -, +, @@ https://stackoverflow.com/questions/55446923/datatables-1-10-using-savestate-to-remember-filtering-and-order-but-need-to-upd/60708638#60708638 --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ a/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -63,6 +63,33 @@ var dataTablesDefaults = { $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").removeClass("disabled"); } }); + }, + stateSave: true, + stateSaveCallback: function (settings, data) { + const state = JSON.stringify(data); + //get query part of the url + let searchParams = new URLSearchParams(window.location.search); + //add encoded state into query part + searchParams.set($(this).attr('id') + '_state', state); + //form url with new query parameter + const newRelativePathQuery = window.location.pathname + '?' + searchParams.toString() + window.location.hash; + //push new url into history object, this will change the current url without need of reload + history.pushState(null, '', newRelativePathQuery); + }, + stateLoadCallback: function (settings) { + const url = new URL(window.location.href); + let state = url.searchParams.get($(this).attr('id') + '_state'); + + //check the current url to see if we've got a state to restore + if (!state) { + return null; + } + + //if we got the state, add current timestamp + state = JSON.parse(state); + state['time'] = Date.now(); + + return state; } }; --