Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(#10210): Hide pager when there is only one page (#10210) #10221

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions openlibrary/plugins/openlibrary/js/editions-table/index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -43,6 +42,7 @@ export function initEditionsTable() {
});

$('#editions').on('length.dt', function(e, settings, length) {
togglePaginationVisibility(length);
localStorage.setItem(LS_RESULTS_LENGTH_KEY, length);
});

Expand All @@ -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);
}
Loading