laravel-datatables
laravel-datatables copied to clipboard
Total amount causing issue with paging
Summary of problem or feature request
When I get the sum of amount it works great but once I'm using the pagination the total amount gets 0.
Laravel/PHP Code ->withQuery('total', function ($filteredQuery) { return $filteredQuery->sum('Amount'); })```
Js Code table.on('draw.dt', function (e) { $('#total').text(LaravelDataTables["dataTableBuilder"].ajax.json().total) });
System details
- Operating System unbntu 19.04
- PHP Version 7.1
- Laravel Version 5.8
- Laravel-Datatables Version 9.0
Any error on the response? Maybe try cloning the filteredQuery
cause it's currently mutable.
->withQuery('total', function ($filteredQuery) {
return (clone $filteredQuery)->sum('Amount');
})
I already tried it before but it didn't work, It works correctly only on the page the first page.
the query I get on the first page is:
select sum([Amount]) as aggregate from [Transaction]
and in other pages I got a query like this:
select * from (select sum([Amount]) as aggregate , row_number() over (order by (select 0)) as row_num from [Transaction]) as temp_table where row_num between 101 and 150 order by row_num
but can I listen to all events that are fired except paging? I think it will solve the problem if there is another one
I see, so the problem is paging are getting applied when doing the sum? Maybe try removing the paging applied on query before applying the sum? Is it possible to remove the limit applied on query? Will dig further when I got the chance.
I have the same issue. Is there any solution for this after 2 years?
any solve on that?
got same problem.
Any Update?? I got the same issue.
@yajra did you got any chance to find solution. i have same problem
There is a work around you guys can do. May be helpful for someone. Compare the start if its 0 then return else return static value and in front check that condition.
"fnDrawCallback": function( oSettings ) { if( oSettings.json.total != 'no' ) { $('#total_donation').text(oSettings.json.total); } },
There is a work around you guys can do. May be helpful for someone. Compare the start if its 0 then return else return static value and in front check that condition.
"fnDrawCallback": function( oSettings ) { if( oSettings.json.total != 'no' ) { $('#total_donation').text(oSettings.json.total); } },
This seems a great workaround! It works perfectly. Really thanks man!!!!
If someone is using datatables as service, in method dataTable has to use
$startNo = $this->request->input("start")
because it's an inherited property.
This works fine for me: ->withQuery('total', function ($filteredQuery) { return (clone $filteredQuery)->offset(0)->sum('Amount'); })
just add ->offset(0)
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been inactive for 7 days since being marked as stale.