Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to all returned data of dataTable query on server #1752

Closed
alr2413 opened this issue May 29, 2018 · 4 comments
Closed

Access to all returned data of dataTable query on server #1752

alr2413 opened this issue May 29, 2018 · 4 comments

Comments

@alr2413
Copy link

alr2413 commented May 29, 2018

Summary of problem or feature request

First, thanks for this awesome package.
I want to calculate the sum of one columns of filtered data on my dataTable and send it to the client as an extra parameters. To make it more clear, assume that the selected column is price of an item and the extra parameter is the summation of price of all available items that is changed based on the requested search parameters.
As mentioned in dataTable docs, we can pass more extra parameters by the "with" method to the client. My problem is that how we can access all data on server.
Also note that this task can not be done in client-side because for a specific search parameters, only a portion of data are returned to the client based on the predefined pagination and the extra parameter (in my case "total price") is fixed for these search parameters.
Thanks.

System details

  • Operating System: macOS High Sierra
  • PHP Version: 7.1.10
  • Laravel Version: 5.6.20
  • Laravel-Datatables Version: 8.6.0
@alr2413
Copy link
Author

alr2413 commented May 29, 2018

I have found a trivial solution.
We can access to all data of dataTable by using $query->get() command in "dataTable" function and iterate over all data to calculate and extract our desired extra parameter. But I think this is not an efficient way if the data size becomes bigger.
I'm going to look for a better implementation way.

@yajra
Copy link
Owner

yajra commented May 30, 2018

There is a less documented api that you can use to get the filtered query. See https://github.com/yajra/laravel-datatables/blob/8.0/CHANGELOG.md#added and #1068 for ref.

$dataTable = Datatables::of(App\User::query());
$response  = $dataTable->toJson();
$total = $dataTable-> getFilteredQuery()->sum('total');
// TODO: append queried total to JsonResponse.
return $response;

@alr2413
Copy link
Author

alr2413 commented May 30, 2018

Thanks a lot.

@alr2413 alr2413 closed this as completed May 30, 2018
yajra added a commit that referenced this issue Jun 3, 2018
Use filteredQuery as callback parameter.
Fix #1752
@yajra
Copy link
Owner

yajra commented Jun 3, 2018

Hey, I just released a better way of doing this on #1758. Kindly give it a try. See also docs for some ref. Thanks!

EDIT
See #1759 instead. Thanks!

yajra added a commit that referenced this issue Jun 3, 2018
* 8.0:
  Bump v8.6.1 🚀
  Fix CS.
  Fix with closue value implementation. Use filteredQuery as callback parameter. Fix #1752
@github-actions github-actions bot locked and limited conversation to collaborators Oct 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants