Laravel-datatables: Multiple datatables in one view

Created on 14 Oct 2017  路  4Comments  路  Source: yajra/laravel-datatables

Summary of problem or feature request

I want to display 2 tables in the same view. My current approach leads to this error:

DataTables warning: table id=dataTableBuilder - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

Code snippet of problem

Controller:

        $builderAssignedIps = $dataTable->getHtmlBuilder();
        $tableAssignedIps = $builderAssignedIps->columns([
            ['data' => 'ip_address', 'name' => 'ip_address', 'title' => 'IP Address'],
            ['data' => 'created_at', 'name' => 'created_at', 'title' => 'Assigned at']
        ]);

        $builderAssignedDomains = $dataTable->getHtmlBuilder();
        $tableAssignedDomains = $builderAssignedDomains->columns([
            ['data' => 'domain', 'name' => 'ip_address', 'title' => 'Domain'],
            ['data' => 'created_at', 'name' => 'created_at', 'title' => 'Assigned at']
        ]);

View:

{!! $tableAssignedIps->ajax(route('get.order.assignedIPAddresses', $purchase))->table() !!}
{!! $tableAssignedDomains->ajax(route('get.order.assignedDomains', $purchase))->table() !!}

{!! $tableAssignedIps->scripts() !!}
{!! $tableAssignedDomains->scripts() !!}

System details

Laravel Version: 5.3
DataTable Version: 6.0

question

All 4 comments

Any help would be appreciated..

Thanks

You need to assign a different table id for each tables.

->table(['id' => 'table-ips'])
->table(['id' => 'table-domain'])

Thanks!

@yajra please give me full example for this code actually response from the controller or maybe add to documentation would be appreciated. This is important stuff
Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jayenn007 picture jayenn007  路  21Comments

faisalhilmi picture faisalhilmi  路  18Comments

phainv picture phainv  路  16Comments

AbuHamdah picture AbuHamdah  路  33Comments

fanjavaid picture fanjavaid  路  32Comments