From 368beca9fa27ce56a9f149601a4fc0c71396082e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 Dec 2024 10:48:28 +0100 Subject: [PATCH] Bug 38255: Allow instantiation without parameters `$(node).kohaTable()` should work. Without this patch we got `Uncaught TypeError: settings is null` Signed-off-by: Lucas Gass --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 20 +++++++++---------- .../opac-tmpl/bootstrap/js/datatables.js | 20 +++++++++---------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 4e54a2e88cb..62b5350c192 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -1029,8 +1029,7 @@ function _dt_save_restore_state(table_settings, external_filter_nodes={}){ * @param {Object} default_filters Add a set of default search filters to apply at table initialisation * @return {Object} The dataTables instance */ - $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options, external_filter_nodes) { - var settings = null; + $.fn.kohaTable = function(options={}, table_settings, add_filters, default_filters, filters_options, external_filter_nodes) { // Early return if the node does not exist if (!this.length) return; @@ -1055,17 +1054,16 @@ function _dt_save_restore_state(table_settings, external_filter_nodes={}){ options.processing = true; options.pagingType = "full_numbers"; } - - settings = $.extend(true, {}, dataTablesDefaults, { - "paging": true, - 'searching': true, - 'language': { - 'emptyTable': (options.emptyTable) ? options.emptyTable : __("No data available in table") - }, - }, options); - } + var settings = $.extend(true, {}, dataTablesDefaults, { + "paging": true, + 'searching': true, + 'language': { + 'emptyTable': (options.emptyTable) ? options.emptyTable : __("No data available in table") + }, + }, options); + settings["buttons"] = _dt_buttons({settings, table_settings}); if ( add_filters ) { diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js index 7190e6ed0ac..1c786951a00 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js @@ -275,8 +275,7 @@ function _dt_visibility(table_settings, table_dt){ * available from the columns_settings template toolkit include * @return {Object} The dataTables instance */ - $.fn.kohaTable = function(options, table_settings){ - var settings = null; + $.fn.kohaTable = function(options={}, table_settings=undefined){ // Early return if the node does not exist if (!this.length) return; @@ -290,17 +289,16 @@ function _dt_visibility(table_settings, table_dt){ dataTablesDefaults.initComplete(settings, json) }; } - - settings = $.extend(true, {}, dataTablesDefaults, { - "paging": true, - 'searching': true, - 'language': { - 'emptyTable': (options.emptyTable) ? options.emptyTable : __("No data available in table") - }, - }, options); - } + var settings = $.extend(true, {}, dataTablesDefaults, { + "paging": true, + 'searching': true, + 'language': { + 'emptyTable': (options.emptyTable) ? options.emptyTable : __("No data available in table") + }, + }, options); + settings["buttons"] = _dt_buttons({settings, table_settings}); if ( table_settings ) { -- 2.34.1