From 99f56bac30adec17b246e7dda0da382260385a46 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 21 Aug 2025 12:32:39 +0000 Subject: [PATCH] Bug 40683: WIP This patch adds a row id which allows the slection to work across pages I played with making the Rigth side export buttons use selected rows - they all work on visible rows at this time We need to fully implement "Select none" to clear across pages Right now the row selection doesn't always match the checkboxes Basically, this needs a lot of work :-) --- .../catalogue/itemsearch_item.json.inc | 2 +- .../prog/en/modules/catalogue/itemsearch.tt | 55 ++----------------- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 17 +++++- 3 files changed, 23 insertions(+), 51 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc index 2367c59f1b2..d2e9652c1dc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc @@ -8,7 +8,7 @@ [%- biblioitem = item.biblioitem -%] [ "[% FILTER escape_quotes = replace('"', '\"') ~%] - + [%~ END %]", "[% FILTER escape_quotes ~%] [% INCLUDE 'biblio-title.inc' | trim | collapse %] 0) { var href = '/cgi-bin/koha/catalogue/item-export.pl?format=' + format; href += '&itemnumber=' + Array.from( item_search_selections ).join('&itemnumber='); @@ -442,19 +443,6 @@ } } - function prepSelections(){ - let item_search_selections = JSON.parse( localStorage.getItem("item_search_selections") ) || []; - if( item_search_selections.length > 0 ){ - showItemSelections( item_search_selections.length ); - $("#results input[type='checkbox']").each(function(){ - var itemnumber = $(this).val(); - if( item_search_selections.indexOf( itemnumber ) >= 0 ){ - $(this).prop("checked", true ); - } - }); - } - } - function getParams($form) { var params = []; $form.find('select:not(:disabled) option:selected,input[type="text"]:not(:disabled),input[type="hidden"]:not(:disabled),input[type="radio"]:checked').each(function() { @@ -649,6 +637,7 @@ "destroy": true, "serverSide": true, "processing": true, + "select": { "style": "multi", "selector": "td:first-child" }, "ajax": { url: '/cgi-bin/koha/catalogue/itemsearch.pl', data: function ( d ) { @@ -692,15 +681,12 @@ { 'name': 'date_due' }, { 'name': 'actions', 'orderable': false, searchable: false, } ], + "rowId": [6], "pagingType": "full_numbers", - "drawCallback": function( settings ) { - prepSelections(); - }, fixedHeader: false // There is a bug on this view }, table_settings, true, null, filters_options ); $('#results').on('draw.dt', function (e, settings) { - prepSelections(); $('[data-bs-toggle="tooltip"]').tooltip(); }); } @@ -763,36 +749,6 @@ }); }); - $("body").on("click", "#clear-row-selection", function(e){ - e.preventDefault(); - $("#results input[type='checkbox']").prop("checked" ,false ).change(); - localStorage.removeItem("item_search_selections"); - showItemSelections( 0 ); - }); - - $("body").on('change', '#results input[type="checkbox"]', function() { - let item_search_selections = JSON.parse( localStorage.getItem("item_search_selections") ) || []; - var itemnumber = $(this).val(); - if( $(this).prop("checked") ){ - item_search_selections.push( $(this).val() ); - localStorage.setItem('item_search_selections', JSON.stringify( item_search_selections )); - showItemSelections( item_search_selections.length ); - } else { - var filtered = item_search_selections.filter(function( value ){ - return value !== itemnumber; - }); - if( filtered.length > 0 ){ - localStorage.setItem('item_search_selections', JSON.stringify( filtered )); - item_search_selections = filtered; - showItemSelections( filtered.length ); - } else { - item_search_selections = []; - localStorage.removeItem('item_search_selections'); - showItemSelections( 0 ); - } - } - }); - $("body").on("click", "#csvExportLink", function(e){ e.preventDefault(); exportItems('csv'); @@ -822,7 +778,8 @@ .attr("name", "del") .attr("id", "batch_mod_del") ); - let item_search_selections = JSON.parse( localStorage.getItem("item_search_selections") ) || []; + var the_table = $("#results").DataTable(); + var item_search_selections = the_table.select.cumulative().rows; // Populate batch forms with itemnumbers in local storage for (let item of item_search_selections){ var field = $("").attr("type","hidden") diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 28d1cf5eee8..6ecc3c5d961 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -38,6 +38,7 @@ var dataTablesDefaults = { }, dom: '<"dt-info"i><"top pager"<"table_entries"lp><"table_controls"fB>>tr<"bottom pager"ip>', buttons: [ + "selectNone", { fade: 100, className: "dt_button_clear_filter", @@ -75,7 +76,7 @@ var dataTablesDefaults = { }, }; DataTable.defaults.column.orderSequence = ["asc", "desc"]; - +//select: { style: 'multi',selector: 'td:first-child' }, function toggledClearFilter(searchText, tableId) { let clear_filter_button = $("#" + tableId + "_wrapper").find( ".dt_button_clear_filter" @@ -837,6 +838,19 @@ function _dt_buttons(params) { format: export_format_spreadsheet, }, }, + { + extend: "excelHtml5", + text: _("Export selected to excel"), + exportOptions: { + columns: exportColumns, + format: export_format_spreadsheet, + // rows: function(idx, data, node) { + // console.log( idx, $(node).find('td:first-child input[type="checkbox"]').is(':checked') ); + // return $(node).find('td:first-child input[type="checkbox"]').is(':checked'); + // }, + modifier: { selected: true }, + }, + }, { extend: "csvHtml5", exportOptions: { @@ -875,6 +889,7 @@ function _dt_buttons(params) { node.addClass("disabled"); }, }); + buttons.push("selectNone"); // Retrieving bKohaColumnsUseNames from the options passed to the constructor, not DT's settings // But ideally should be retrieved using table.data() -- 2.39.5