From d8d216fb632209f63296a0cdd6bdea4eec8549f6 Mon Sep 17 00:00:00 2001 From: elias Date: Fri, 12 Dec 2025 09:31:29 +0000 Subject: [PATCH] Bug 40906: Dropdown sort button in mana import UI Using the datatable "collection" button, i added a dropdown menu to the datatable, making it possible to sort results, so no feature are lost in the patch. --- koha-tmpl/intranet-tmpl/prog/css/reports.css | 1 - koha-tmpl/intranet-tmpl/prog/js/datatables.js | 4 ++ koha-tmpl/intranet-tmpl/prog/js/mana.js | 55 ++++++++++++++++++- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/css/reports.css b/koha-tmpl/intranet-tmpl/prog/css/reports.css index 09016f6be40..3263a22ff7d 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/reports.css +++ b/koha-tmpl/intranet-tmpl/prog/css/reports.css @@ -92,7 +92,6 @@ del { .report-description { height:5rem; - word-wrap: break-word; } #mana_results_datatable .w-40 { diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 6ebe226e186..7c82c2ecdfb 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -1462,6 +1462,10 @@ function update_search_description( settings["buttons"] = _dt_buttons({ settings, table_settings }); + if (options.buttons) { + settings["buttons"].push(options.buttons); + } + if (add_filters) { settings["orderCellsTop"] = true; } diff --git a/koha-tmpl/intranet-tmpl/prog/js/mana.js b/koha-tmpl/intranet-tmpl/prog/js/mana.js index 98fe2054a26..8ff3e1f2877 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/mana.js +++ b/koha-tmpl/intranet-tmpl/prog/js/mana.js @@ -171,9 +171,15 @@ $(document).ready(function () { var dataSet = { _page: Math.floor(start / length) + 1, _per_page: length, - _order_by: "", }; + if (data.order[0]) { + dataSet._order_by = + data.columns[data.order[0].column].data + + ":" + + data.order[0].dir; + } + //This is why the kohaTables data function is overwritten, to allow passing the search query as a string. if (data.search) { dataSet.q = data.search.value; @@ -184,7 +190,6 @@ $(document).ready(function () { createdRow: function (row, data, dataIndex) { let template = $("#report-details-template")[0]; const clone = document.importNode(template.content, true); - //changer id de la row const title = clone.querySelector("span"); const description = clone.querySelectorAll("td")[1]; const nbofuser_place = clone.querySelector(".report_info"); @@ -215,6 +220,52 @@ $(document).ready(function () { { data: "nbofusers" }, { data: "lastimport" }, ], + dom: '<"dt-info"i><"top pager"<"table_entries"lp><"table_controls"fB>>tr<"bottom pager"ip>', + buttons: [ + { + extend: "collection", + text: 'Sort by', + attr: { id: "sort-by-button" }, + align: "button-right", + buttons: [ + { + text: __("Name (A-Z)"), + action: function (e, dt, node, config) { + dt.order([1, "asc"]).draw(); + $(".dt-button-background").trigger("click"); + }, + }, + { + text: __("Name (Z-A)"), + action: function (e, dt, node, config) { + dt.order([1, "desc"]).draw(); + $(".dt-button-background").trigger("click"); + }, + }, + { + text: __("Date (from newest)"), + action: function (e, dt, node, config) { + dt.order([4, "desc"]).draw(); + $(".dt-button-background").trigger("click"); + }, + }, + { + text: __("Date (from oldest)"), + action: function (e, dt, node, config) { + dt.order([4, "asc"]).draw(); + $(".dt-button-background").trigger("click"); + }, + }, + { + text: __("Popularity"), + action: function (e, dt, node, config) { + dt.order([3, "desc"]).draw(); + $(".dt-button-background").trigger("click"); + }, + }, + ], + }, + ], }); let thead = $("#mana_results_datatable thead"); -- 2.39.5