A simple package to ease datatable.js server side operations
This package is created to handle server-side and client-side works of DataTables jQuery Plugin via AJAX option by using Eloquent ORM, Query Builder or Collection.
Version 4.x continues the improvements in version 3.x by introducing some new features
-
Added support for select raw queries
-
Auto guess column names if no columns are provided in request
-
Auto guess column names if * is provided in column names
-
Added support for group by and havig clause
-
Example
echo datatable(User::select('users.name','users.email','users.contact_no','users.role_id') ->selectRaw(" Max(id) as total ") ->groupBy('users.name', 'users.email', 'users.contact_no'))->init(); echo datatable(User::select('users.*'))->init();
-
Added Support For Data Filtering From Client Side
-
Added Column Wise Search Query Support Using Below Api
-
Example
{ "columns": [ { "data": "name", "name": "name", "searchable": true, "orderable": true, "search": { "value": "", "regex": false } } ], "start": 0, "length": 10, "search": { "value": "Yoges", "regex": false }, "filters": { "role_id" : [1,2],// role id in 1,2 "created_at": [date1, date2], // createde at is between date1 and date2, "name": "iyogesh" // where name = iyogesh } }
Modified datatable function to support server side export to xls,csv and json
You just need to pass 2 new arguments in query-string/body export
and ext
if export = true
it will return download file response
for ext
default value is xlsx
https://datatable-url?export=true&ext=xlsx
echo datatable()->of(User::query())->init();
echo datatable()->of(DB::table('users')->join1()->join2()->select(column1,column2,...columnK))->init();
echo datatable()->of(DB::table('users'))->init();
echo datatable()->of(User::all())->init();
echo datatables(User::query());
echo datatables(DB::table('users')->join1()->join2()->select(column1,column2,...columnK));
echo datatables(DB::table('users'));
echo datatables(User::all());
use Datatable;
echo Datatable::of(User::query())->init();
echo Datatable::of(DB::table('users')->join1()->join2()->select(column1,column2,...columnK))->init();
echo Datatable::of(DB::table('users'))->init();
echo Datatable::of(User::all())->init();
echo Datatable::make(User::query());
echo Datatable::make(DB::table('users')->join1()->join2()->select(column1,column2,...columnK));
echo Datatable::make(DB::table('users'));
echo Datatable::make(User::all());
use Datatable;
echo Datatable::of(User::query())->add(columnName,function($user){
return "<a href='' id='$user->id'>$user->name</a>";
})->init();
echo datatable()->of(User::query())->add(columnName,function($user){
return "<a href='' id='$user->id'>$user->name</a>";
})->init();
use Datatable;
echo Datatable::of(User::query())->addColumns([columnName1=>function($user){
return "<a href='' id='$user->id'>$user->name</a>";
},columnName2=>function($user){
return "<a href='' id='$user->id'>$user->name</a>";
}...])->init();
use Datatable;
echo Datatable::of(User::query())->remove(columnName)->init();
use Datatable;
echo Datatable::of(User::query())->remove([columnName1,columnName2,...])->init();
- PHP >= 7.0
- Laravel 7.x
- jQuery DataTables v1.10.x
- You can check previous release for different version of laravel
$ composer require iyogesharma/datatable-laravel:"~1.0"
Register provider and facade on your config/app.php
file.
'providers' => [
...,
YS\Datatable\DatatableServiceProvider::class,
]
'aliases' => [
...,
'Datatable' => YS\Datatable\Facades\Datatable::class,
"Table"=>YS\\Datatable\\Facades\\Table::class
]
before </body>
tag add
{{table()->css()}}
before </body>
tag add
{{table()->scripts()}}
before </body>
tag add
{{table()->dependencies()}}
In HTMl file inside document .ready function write
{{table()->basic()}}
In HTMl file inside document .ready function write
{{table()->ajax($url,$columns,$configs)}}
{{table()->dependencies()}}
<script>
$(document).ready(function(){
{{ table()->ajax('ddd/ddd',
[ 'name',
'email',
'office'
],[
'paging'=>'true',
'fixedheader'=>'true',
'buttons'=>['colvis','copy','csv','print'],
'order'=>[[0,'desc']],
'lengthMenu'=> [[ 10, 20, 30, 40, 50], [ 10, 20, 30, 40, 50]],
]
)}}
})
</script>
The MIT License (MIT). Please see License File for more information.