singlequote / Laravel-datatables

This repo contains a Datatable that can render a filterable and sortable table. It aims to be very lightweight and easy to use. It has support for retrieving data asynchronously, pagination and recursive searching in relations.
https://singlequote.github.io/Laravel-datatables/
MIT License
18 stars 6 forks source link

Two or more Datatables at the same time #13

Closed kastoras closed 5 years ago

kastoras commented 5 years ago

Hello,

I have problem when i try to have two datatables in the same Page.

Initialise datatables:

$companytable = \DataTable::model(\App\Company::class)->tableModel(\App\TableModels\Companies::class);

$producttable = \DataTable::model(\App\Product::class)->tableModel(\App\TableModels\Products::class);

Send to view: return view('view_file',[ ])->with(compact('companytable','producttable'));

Try to use them on view file:

 {!! $companytable->table() !!}
 {!! $companytable->script() !!}

 {!! $producttable->table() !!}
 {!! $producttable->script() !!}

With this code i get Datatables error:

DataTables warning: table id=laravelDataTable5d5d52687a111 - Ajax error.

Is it possible to do something like this or i can have only one datatable per page;

Thanks in advance.

wimurk commented 5 years ago

Hi @kastoras,

Can you show me the complete error trace of the datatable response?

wimurk commented 5 years ago

Hi @kastoras,

I reproduced the problem. The package can't handle 2 or more tables at onces. In the next version update the issue will be fixed.

kastoras commented 5 years ago

Ok thank you, if i will find a solution i will let you know.

wimurk commented 5 years ago

issue is fixed in #15 see the changes.

The problem is with the Facade. It overwrites the tables. You can use multiple tables by directly calling the package controller.

use SingleQuote\DataTables\DataTable;

$companytable =(new DataTable)->model(\App\Company::class)->tableModel(\App\TableModels\Companies::class);

$producttable = (new DataTable)->model(\App\Product::class)->tableModel(\App\TableModels\Products::class);