From da047caff5b453b2f7a2a37cf789592c6c82217e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 11 Apr 2023 14:58:59 +0100 Subject: [PATCH] Bug 33484: Make saveState column handling global This patch updates the handling for saveState added in bug 22276 to work globally for all KohaTables that pass a table_settings hash. Signed-off-by: Pedro Amorim Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- .../prog/en/includes/columns_settings.inc | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc index 9bb0f982ba0..1e45ef30f5d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc @@ -11,7 +11,26 @@ function KohaTable(id_selector, dt_parameters, table_settings, add_filters) { var selector = '#' + id_selector; if ( table_settings ) { - var columns_settings = table_settings['columns']; + + var table_key = + 'DataTables_' + + table_settings['module'] +'_' + + table_settings['page'] +'_' + + table_settings['table']; + + // enable stateSave + dt_parameters['stateSave'] = true; + dt_parameters['stateSaveCallback'] = function( settings, data ) { + localStorage.setItem( table_key, JSON.stringify(data) ) + } + dt_parameters['stateLoadCallback'] = function(settings) { + return JSON.parse( localStorage.getItem(table_key) ) + } + + // merge stateSave for column settings + var local_settings = localStorage.getItem(table_key); + var system_settings = table_settings['columns']; + var columns_settings = get_columns_saved_state(local_settings, system_settings); $(columns_settings).each( function() { var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector + ' th' ); -- 2.34.1