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
How can I assign Global variable for all row. #1242
Comments
global? just pass the variable on closure? $status = getUserStatus($user->id);
return Datatables::of($users)
->addColumn('status', function ($user) use ($status) {
return $status;
}); |
I want the status to be change in each iteration
please don't close the issue before developer's review. |
If you want it on each iteration then it's not GLOBAL. ->addColumn('status', function ($user) {
return getUserStatus($user->id);
}); |
For each add or edit column I need to call the same function. that will make call to the MySql query so if I have 5 column using this same function then In one iteration same MySql query call for 5 times and for 1000 records it will be 1000 * 5 = 5000 duplicate query. If I use paging then also for minimum of 20 records 20 * 5 = 100 duplicate queries. |
Use eager loading if you want to solve N+1 issues. See this demo for ref: https://datatables.yajrabox.com/relation/belongs-to |
Or use join statements and include the status on your query. |
Query is this much complicate. Don't think eager loading will be possible |
To use getXYZ and setXYZ functions inside add and edit Column, we compulsory need an object of Eloquent. |
Ok didn't expected that much complicated query. ^_^ May consider using cache then? If status doesn't change very often, then you can also set it for a longer period of time. -- Edit -- function getUserStatus($id) {
return Cache::remember('user.status.'.$id, 1, function($id) {
return Status::find($id);
});
} |
Hope to something like this would be there |
Not really sure on your suggestion |
I really look for a way out to get rid of 100s of duplicate queries. just because to call getXYZ and setXYZ in more than one column. |
I have also the same issue and wants to use a global (common) variable so that i can use it for each iteration as a common variable Thanks for the help in advance.. :) |
same @ruchisheth |
@rajanjain and @haratmalli I haven't got any solution for this. |
hi did you try in the first column to put data->statues = 4; call it on the second callback? |
Summary of problem or feature request
I need to set one variable at each iteration of data table in use it all addColumn() and editColumn() function.
Code snippet of problem
Something like
so, each time I don't need to call this getUserStatus($user->id) function.
System details
The text was updated successfully, but these errors were encountered: