diff --git a/openlibrary/plugins/openlibrary/js/editions-table/index.js b/openlibrary/plugins/openlibrary/js/editions-table/index.js old mode 100644 new mode 100755 index 4faa082d0f3..d092558fbdf --- a/openlibrary/plugins/openlibrary/js/editions-table/index.js +++ b/openlibrary/plugins/openlibrary/js/editions-table/index.js @@ -6,7 +6,6 @@ const LS_RESULTS_LENGTH_KEY = 'editions-table.resultsLength'; export function initEditionsTable() { var rowCount; - let currentLength; $('#editions th.title').on('mouseover', function(){ if ($(this).hasClass('sorting_asc')) { @@ -43,6 +42,7 @@ export function initEditionsTable() { }); $('#editions').on('length.dt', function(e, settings, length) { + togglePaginationVisibility(length); localStorage.setItem(LS_RESULTS_LENGTH_KEY, length); }); @@ -53,29 +53,31 @@ export function initEditionsTable() { }) rowCount = $('#editions tbody tr').length; - if (rowCount < 4) { - $('#editions').DataTable({ - aoColumns: [{sType: 'html'},null], - order: [ [1,'asc'] ], - bPaginate: false, - bInfo: false, - bFilter: false, - bStateSave: false, - bAutoWidth: false - }); - } else { - currentLength = Number(localStorage.getItem(LS_RESULTS_LENGTH_KEY)); - $('#editions').DataTable({ - aoColumns: [{sType: 'html'},null], - order: [ [1,'asc'] ], - lengthMenu: [ [3, 10, 25, 50, 100, -1], [3, 10, 25, 50, 100, 'All'] ], - bPaginate: true, - bInfo: true, - sPaginationType: 'full_numbers', - bFilter: true, - bStateSave: false, - bAutoWidth: false, - pageLength: currentLength ? currentLength : DEFAULT_LENGTH - }); + const currentLength = Number(localStorage.getItem(LS_RESULTS_LENGTH_KEY)) || DEFAULT_LENGTH; + + $('#editions').DataTable({ + aoColumns: [{ sType: 'html' }, null], + order: [[1, 'asc']], + lengthMenu: [[3, 10, 25, 50, 100, -1], [3, 10, 25, 50, 100, 'All']], + bPaginate: true, // Always allow pagination initially + bInfo: true, + sPaginationType: 'full_numbers', + bFilter: true, + bStateSave: false, + bAutoWidth: false, + pageLength: currentLength, + }); + + // Toggle pagination visibility based on row count and selected length + function togglePaginationVisibility(selectedLength) { + const paginationElement = $('.dataTables_paginate.paging_full_numbers'); + if (rowCount <= selectedLength || selectedLength === -1) { + paginationElement.hide(); + } else { + paginationElement.show(); + } } + + // Initial pagination visibility toggle + togglePaginationVisibility(currentLength); }