简体   繁体   English

获取 laravel 背包中特定列的总和(无分页)

[英]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.使用数据表,我得到了正在绘制的记录,但我找不到如何拦截 ajax 查询或修改它以获取该列的完整总数,包括过滤器修改。

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).实现这一目标的一种方法是覆盖ListOperationsearch() function(它是表 ajax 端点)。

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干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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