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 to render 2 datatable in one page different tabs #1202
Comments
However, i don't like very much to use service-based approach for a table then different for another. For consistent, i would like to know how to separate even further ..is it possible to create such a structure?: UsersDatatableController PostsDatatableController UsersController Since my use case is for rendering serverside datatable, looking to combine with @yajra |
@isometriq atm, I think you cannot use two DataTable class within the same route for ajax handling by default. However, maybe you can add additional param that you can use to identify which ajax response is being requested. public function index(UsersDatatable $udt, PostsDatatable $pdt) {
if (request()->get('table') == 'posts') {
return $udt->render('my.view', compact('udt', 'pdt'));
}
return $pdt->render('my.view', compact('udt', 'pdt'));
} You can then use the builder for both DT on your view. {!! $udt->html()->table() !!} // users table
{!! $pdt->html()->table() !!} // posts table
{!! $udt->scripts() !!} // users table scripts
{!! $pdt->scripts() !!} // posts table scripts Just an idea that you can try exploring. Thanks! |
Thanks @yajra i'll try a couple things |
Thanks for this question. I just got this to work as @yajra suggested. For people who are trying to do the same thing and landed on this post, the view file should be:
You need to pass in an unique id attribute to each table so the js will work properly. Hope this help somebody! And in your DataTable class, you passed in the additional param in the html() method:
@yajra, would be nice if the latest documentation on https://datatables.yajrabox.com/services/two-datatables have this example instead. |
Hi all, I followed the solution on this post and I achieved my two datatables working at the same time! I want that to load the 2nd datatable when I click a specific tab/button.
That consists basically to add a if statement wrapping the JS of datatable, but I want a solution through DataTable Service implementation, like you were doing in this post. Something like this:
But this can't be done because the function "scripts()" print the tags <script></script> itself. I don't know if what I'm asking is very easy to solve, or I'll have to write manually the JavaScript of the datatable and dispense DataTable Service in the second table. Thanks for your attention. @yajra |
I have tried to use your suggestion but i got an error |
"One" liner: public function show(PrimaryDataTable $primaryDataTable, SecondDataTable $secondDataTable)
{
/** Depend request we need to match proper class */
return ${request()->get('table', 'primary') . 'DataTable'}->render(
'resource.show',
compact('primaryDataTable', 'secondDataTable')
);
} also be carefull with minified ajax, add ajax data after calling this method. |
Summary of problem or feature request
Hi, good day to you.
I wanna ask something and need your help, i created page that had 2 tabs, tab #one is showing data per day, tab #two is showing data per hour, i try to make the same table in that two tabs, but its only showing in tab #one, in tab #two only showing name of column, why this happen?
Code snippet of problem
i suspected the wrong thing is in my controller, this is the code:
so i wanna ask how to render multiple datatable in controller.
Thankyou.
Oh and this is the code in my index.blade.php
System details
The text was updated successfully, but these errors were encountered: