From cfa5c832c2b0580ad7fc98d25ce1ca498a30297e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 16 Nov 2024 08:05:05 +0100 Subject: [PATCH] Bug 38436: Do not deal with 'Columns' button if no table settings If the table does not have table settings we should not deal with the column visibility and not display the 'Columns' button. Signed-off-by: Owen Leonard --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index f7d1ebb4a3..a17e183b2a 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -668,12 +668,19 @@ function _dt_buttons(params){ // But ideally should be retrieved using table.data() let use_names = settings.bKohaColumnsUseNames; let included_columns = []; - if ( use_names ) { - // bKohaColumnsUseNames is set, identify columns by their data-colname - included_columns = table_settings.columns.filter(c => !c.cannot_be_toggled).map(c => "[data-colname='%s']".format(c.columnname)).join(','); - } else { - // Not set, columns are ordered the same than in the columns settings - included_columns = table_settings.columns.map((c, i) => !c.cannot_be_toggled ? i : null).filter(i => i !== null); + if (table_settings) { + if (use_names) { + // bKohaColumnsUseNames is set, identify columns by their data-colname + included_columns = table_settings.columns + .filter(c => !c.cannot_be_toggled) + .map(c => "[data-colname='%s']".format(c.columnname)) + .join(","); + } else { + // Not set, columns are ordered the same than in the columns settings + included_columns = table_settings.columns + .map((c, i) => (!c.cannot_be_toggled ? i : null)) + .filter(i => i !== null); + } } if( included_columns.length > 0 ){ buttons.push( -- 2.39.5