From 96b03e3a5bec52662fd84756b48b1f5aa7ea1b8b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 8 Oct 2024 14:58:16 +0200 Subject: [PATCH] Bug 33484: Fix Vue tables datatables.net-vue3 does not use a specific id, and does not let us pass one. It is generated, like: DataTables_Table_0 (and increment when a new table is created). So it's not possible to use this id: it can change and so is not reliable. I have tried to pass "data-koha-table-id" with a specific id (KohaTable_agreements). Which was working, but actually we could simply use the table settings key to identify the tables in the URL. Signed-off-by: Pedro Amorim Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- .../prog/en/includes/columns_settings.inc | 10 +++++++--- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) 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 0ed07f3867..8ede3d3168 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc @@ -39,7 +39,7 @@ function KohaTable(id_selector, dt_parameters, table_settings, add_filters) { // Load state from URL const url = new URL(window.location.href); - let state_from_url = url.searchParams.get( settings.nTable.id + '_state'); + let state_from_url = url.searchParams.get( table_key + '_state'); if ( state_from_url ) { settings.loaded_from_state = true; return JSON.parse(atob(state_from_url)); @@ -221,11 +221,15 @@ function KohaTable(id_selector, dt_parameters, table_settings, add_filters) { titleAttr: __("Copy conditions"), text: ' ' + __("Copy conditions") + '', action: function (e, dt, node, config) { + let table_key = 'DataTables_%s_%s_%s'.format( + table_settings.module, + table_settings.page, + table_settings.table); + let state = JSON.stringify(dt.state()); delete state.time; let searchParams = new URLSearchParams(window.location.search); - let table_id = dt.table().node().id; - searchParams.set(table_id + '_state', btoa(state)); + searchParams.set(table_key + '_state', btoa(state)); let url = window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash; if( navigator.clipboard && navigator.clipboard.writeText){ navigator.clipboard.writeText( url ); diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 73a0d1eea4..f42eeb6c8a 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -767,11 +767,15 @@ function _dt_buttons(params){ titleAttr: __("Copy conditions"), text: ' ' + __("Copy conditions") + '', action: function (e, dt, node, config) { + let table_key = 'DataTables_%s_%s_%s'.format( + table_settings.module, + table_settings.page, + table_settings.table); + let state = JSON.stringify(dt.state()); delete state.time; let searchParams = new URLSearchParams(window.location.search); - let table_id = dt.table().node().id; - searchParams.set(table_id + '_state', btoa(state)); + searchParams.set(table_key + '_state', btoa(state)); let url = window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash; if( navigator.clipboard && navigator.clipboard.writeText){ navigator.clipboard.writeText( url ); @@ -983,7 +987,7 @@ function _dt_save_restore_state(table_settings){ // Load state from URL const url = new URL(window.location.href); - let state_from_url = url.searchParams.get( settings.nTable.id + '_state'); + let state_from_url = url.searchParams.get( table_key + '_state'); if ( state_from_url ) { settings.loaded_from_state = true; return JSON.parse(atob(state_from_url)); -- 2.39.5