Bug 42617: (41512 follow-up) Remove ownPagination and fix recordsFiltered propagation

ownPagination set recordsFiltered on json.data instead of json, causing
DataTables to display "NaN total entries". Remove the artificial 5000
mechanism, propagate real counts from plugins that provide them, and
fall back to actual result counts for those that don't. Also removes a
dead drawCallback overwritten before it could fire.

Test plan:
1) Install this test version of the unpaywall plugin:
https://github.com/openfifth/koha-plugin-ill-avail-unpaywall/releases/tag/test
2) Enable ILLModule and ILLCheckAvailability
3) Configure the plugin and add any emaill address
4) Create a new ILL request:
<staff_url>/cgi-bin/koha/ill/ill-requests.pl?method=create&backend=Standard
5) Enter '42' for cardnumber, any library, and any DOI e.g. '123'.
6) Verify that pagination works as expected

Before patch, pagination controls dont show and the following label is shown:
No entries to show (filtered from NaN total entries)

Signed-off-by: Edith Speller <Edith.Speller@ukhsa.gov.uk>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Pedro Amorim 2026-05-15 13:58:20 +00:00 committed by Lucas Gass
parent 499f7e595e
commit 9b3751f507
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 11 additions and 54 deletions

View File

@ -15,16 +15,6 @@ $(document).ready(function () {
};
window.doSearch = function () {
// In case the source doesn't supply data required for DT to calculate
// pagination, we need to do it ourselves
var ownPagination = false;
var directionSet = false;
var start = 0;
var forward = true; // true == forward, false == backwards
// Arbitrary starting value, it will be corrected by the first
// page of results
var pageSize = 20;
var tableTmpl = {
ajax: {
cache: true, // Prevent DT appending a "_" cache param
@ -104,23 +94,18 @@ $(document).ready(function () {
tableDef.ajax.dataSrc = function (json) {
let data = json.data;
var results = data.results.search_results;
// The source appears to be returning it's own pagination
// data
if (
data.hasOwnProperty("recordsFiltered") ||
data.hasOwnProperty("recordsTotal")
) {
return results;
if (data.hasOwnProperty("recordsFiltered")) {
json.recordsFiltered = data.recordsFiltered;
}
if (data.hasOwnProperty("recordsTotal")) {
json.recordsTotal = data.recordsTotal;
}
if (json.recordsFiltered === undefined) {
json.recordsFiltered = results.length;
}
if (json.recordsTotal === undefined) {
json.recordsTotal = results.length;
}
// Set up our own pagination values based on what we just
// got back
ownPagination = true;
directionSet = false;
pageSize = results.length;
// These values are completely arbitrary, but they enable
// us to display pagination links
((data.recordsFiltered = 5000), (data.recordsTotal = 5000));
return results;
};
tableDef.ajax.data = function (data) {
@ -139,13 +124,6 @@ $(document).ready(function () {
if (data.hasOwnProperty("search")) {
delete data.search;
}
// If we're handling our own pagination, set the properties
// that DT will send in the request
if (ownPagination) {
start = forward ? start + pageSize : start - pageSize;
data.start = start;
data["length"] = pageSize;
}
// We may need to restrict the service IDs being queries, this
// needs to be handled in the plugin's API module
var restrict = $("#service_id_restrict").attr(
@ -178,27 +156,6 @@ $(document).ready(function () {
}
}
}
// Create event watchers for the "next" and "previous" pagination
// links, this enables us to set the direction the next request is
// going in when we're doing our own pagination. We use "hover"
// because the click event is caught after the request has been
// sent
tableDef.drawCallback = function () {
$(
".dt-paging-button.next:not(.disabled)",
this.api().table().container()
).on("hover", function () {
forward = true;
directionSet = true;
});
$(
".dt-paging-button.previous:not(.disabled)",
this.api().table().container()
).on("hover", function () {
forward = false;
directionSet = true;
});
};
// Initialise the table
// Since we're not able to use the columns settings in core,
// we need to mock the object that it would return