@@ -, +, @@ --- Koha/REST/Plugin/Objects.pm | 20 ++++++++----------- Koha/REST/Plugin/Pagination.pm | 4 +++- Koha/REST/V1/Checkouts.pm | 12 +++++------ Koha/REST/V1/Patrons.pm | 17 ++++++++-------- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 3 +++ .../opac-tmpl/bootstrap/js/datatables.js | 3 +++ 6 files changed, 32 insertions(+), 27 deletions(-) --- a/Koha/REST/Plugin/Objects.pm +++ a/Koha/REST/Plugin/Objects.pm @@ -124,19 +124,15 @@ sub register { } # Perform search my $objects = $result_set->search( $filtered_params, $attributes ); + my $total = $result_set->search->count; - if ($objects->is_paged) { - $c->add_pagination_headers({ - total => $objects->pager->total_entries, - params => $args, - }); - } - else { - $c->add_pagination_headers({ - total => $objects->count, - params => $args, - }); - } + $c->add_pagination_headers( + { + total => ($objects->is_paged ? $objects->pager->total_entries : $objects->count), + base_total => $total, + params => $args, + } + ); return $objects->to_api({ embed => $embed }); } --- a/Koha/REST/Plugin/Pagination.pm +++ a/Koha/REST/Plugin/Pagination.pm @@ -50,7 +50,7 @@ sub register { Adds a Link header to the response message $c carries, following RFC5988, including the following relation types: 'prev', 'next', 'first' and 'last'. -It also adds X-Total-Count, containing the total results count. +It also adds X-Total-Count containing the total results count, and X-Base-Total-Count containing the total of the non-filtered results count. If page size is omitted, it defaults to the value of the RESTdefaultPageSize syspref. @@ -61,6 +61,7 @@ If page size is omitted, it defaults to the value of the RESTdefaultPageSize sys my ( $c, $args ) = @_; my $total = $args->{total}; + my $base_total = $args->{base_total}; my $req_page = $args->{params}->{_page} // 1; my $per_page = $args->{params}->{_per_page} // C4::Context->preference('RESTdefaultPageSize') // 20; @@ -114,6 +115,7 @@ If page size is omitted, it defaults to the value of the RESTdefaultPageSize sys # Add X-Total-Count header $c->res->headers->add( 'X-Total-Count' => $total ); + $c->res->headers->add( 'X-Base-Total-Count' => $base_total ); return $c; } ); --- a/Koha/REST/V1/Checkouts.pm +++ a/Koha/REST/V1/Checkouts.pm @@ -90,13 +90,13 @@ sub list { # Perform search my $checkouts = $checkouts_set->search( $filtered_params, $attributes ); + my $total = $checkouts_set->search->count; - if ($checkouts->is_paged) { - $c->add_pagination_headers({ - total => $checkouts->pager->total_entries, - params => $args, - }); - } + $c->add_pagination_headers({ + total => ($checkouts->is_paged ? $checkouts->pager->total_entries : $checkouts->count), + base_total => $total, + params => $args, + }); return $c->render( status => 200, openapi => $checkouts->to_api ); } catch { --- a/Koha/REST/V1/Patrons.pm +++ a/Koha/REST/V1/Patrons.pm @@ -82,14 +82,15 @@ sub list { if $restricted; my $patrons = $patrons_rs->search( $filtered_params, $attributes ); - if ( $patrons_rs->is_paged ) { - $c->add_pagination_headers( - { - total => $patrons->pager->total_entries, - params => $args, - } - ); - } + my $total = $patrons_rs->search->count; + + $c->add_pagination_headers( + { + total => ($patrons->is_paged ? $patrons->pager->total_entries : $patrons->count), + base_total => $total, + params => $args, + } + ); return $c->render( status => 200, openapi => $patrons->to_api ); } --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ a/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -544,6 +544,9 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { json.recordsTotal = total; json.recordsFiltered = total; } + if(total = this._xhr.getResponseHeader('x-base-total-count')) { + json.recordsTotal = total; + } return JSON.stringify(json); }, 'data': function( data, settings ) { --- a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js +++ a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js @@ -207,6 +207,9 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { json.recordsTotal = total; json.recordsFiltered = total; } + if(total = this._xhr.getResponseHeader('x-base-total-count')) { + json.recordsTotal = total; + } return JSON.stringify(json); }, 'data': function( data, settings ) { --