简体   繁体   中英

Getting sum complete (without pagination) of particular columns in backpack for laravel

I followed the recommendations I found here

    jQuery(document).ready(function($) {
        jQuery.fn.dataTable.Api.register( 'sum()', function ( ) {
            return this.flatten().reduce( function ( a, b ) {
                if ( typeof a === 'string' ) {
                    a = a.replace(/[^\d.-]/g, '') * 1;
                }
                if ( typeof b === 'string' ) {
                    b = b.replace(/[^\d.-]/g, '') * 1;
                }
                return a + b;
            }, 0 );
        } );
        
        $("#crudTable tfoot").css("display", "table-footer-group");

        crud.table.on("draw.dt", function ( row, data, start, end, display ) {
            total = crud.table.rows( function ( idx, data, node ) {
                return data[11].includes('Cancelado') ? false : true;} ).data().pluck(10).sum();
            total = "$" +  total.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
            $("#crudTable tfoot tr th").html(
                "&nbsp; <br> &nbsp;"
              );
            $("#crudTable tfoot tr").children().eq(10).html(
                "Total <br>"+  total
              );
        });
});

And I added some modifications to get the total of the column by skipping the items that have canceled status, but I have not been able to get the total of the records but without paging. With Datatable I get the records that are being drawn, but I can't find how to intercept the ajax query or modify it to get the full total on that column including filter modifications.

Currently if in the pagination I request "show all records" obviously I get the value I need. But the requirement is that this value is displayed even if the table is visually paginated.

one way to achieve that would be to overwrite the search() function of the ListOperation (it's the table ajax endpoint).

You would need do do the full query without the pagination part to get the full data, and then pass the calculation along with the paginated response for display.

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM