Laravel-datatables: Insert two datatables in one view page

Created on 20 Oct 2020  路  3Comments  路  Source: yajra/laravel-datatables

Hello, I want to insert two datatables in one view.

this is my controller

    public function create(PlaceDataTable $placeDataTable, EmailRecipientsDataTable $emailRecipientsDataTable)
    {
        return $placeDataTable ->render('digest-report.create');
    }

this is my HTML view

<form id="setting-form" action="#" method="POST" class="wizard-big"
                              action="{{route ('place.store')}}">
                            <h1>Customer</h1>
                                <div class="table-responsive">
                                    {!! $dataTable->table(['id' => 'place-table','class' => 'table table-striped table-bordered table-hover'], false) !!}
                                </div>
                                    <div class="table-responsive">
                                                {!! $dataTable->table(['id' => 'emailrecipients-table','class' => 'table table-striped table-bordered table-hover'], false) !!}
                                   </div>

this is my javascript

{!! $dataTable->scripts() !!}

I trying to add EmailRecipientsDataTable to controller for render the datatable in the view, but I can't return two values on my controller

then I want to make the datatable clickable to capture the row data and be able to use it in the view

what is the best way for this?

question

Most helpful comment

You can use datatables:html.

To create a DT with extracted builder.

php artisan datatables:make Recipients --builder   

To create an HTML builder

php artisan datatables:html Recipients

Usage

    public function create(PlaceDataTable $placeDataTable)
    {
       $recipients = RecipientsDataTableHtml::make();

        return $placeDataTable ->render('digest-report.create', compact('recipients');
    }

// view

{!! $dataTable->table() !!}
{!! $recipients->table() !!}

{!! $dataTable->scripts() !!}
{!! $recipients->scripts() !!}

All 3 comments

You can use datatables:html.

To create a DT with extracted builder.

php artisan datatables:make Recipients --builder   

To create an HTML builder

php artisan datatables:html Recipients

Usage

    public function create(PlaceDataTable $placeDataTable)
    {
       $recipients = RecipientsDataTableHtml::make();

        return $placeDataTable ->render('digest-report.create', compact('recipients');
    }

// view

{!! $dataTable->table() !!}
{!! $recipients->table() !!}

{!! $dataTable->scripts() !!}
{!! $recipients->scripts() !!}

thanks!

Have you tried it? Is it run successfully? If yes can you give how you use it? @andrecuellar

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MahdiPishguy picture MahdiPishguy  路  17Comments

Yahav picture Yahav  路  16Comments

baig772 picture baig772  路  14Comments

ZAZmaster picture ZAZmaster  路  15Comments

faisalhilmi picture faisalhilmi  路  18Comments