1. Go to this page and download the library: Download distilleries/datatable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
<link rel="stylesheet" type="text/css" href="/assets/css/jquery.dataTables.css">
<script type="text/javascript" src="/assets/js/jquery.js"></script>
<script type="text/javascript" src="/assets/js/jquery.dataTables.min.js"></script>
{{ Datatable::table()
->addColumn('id','Name') // these are the column headings to be shown
->setUrl(route('api.users')) // this is the route where data will be retrieved
->render() }}
public function getDatatable()
{
return Datatable::collection(User::all(array('id','name')))
->showColumns('id', 'name')
->searchColumns('name')
->orderColumns('id','name')
->make();
}
$table = Datatable::table()
->addColumn('Email2','Email', "Test")
->noScript();
// to render the table:
$table->render()
// later in the view you can render the javascript:
$table->script();
$column = new TextColumn('foo', 'bar'); // Will always return the text bar
//$column = new FunctionColumn('foo', function($model){return $model->bar}); // Will return the bar column
//$column = new DateColumn('foo', DateColumn::TIME); // Will return the foo date object as toTimeString() representation
//$column = new DateColumn('foo', DateColumn::CUSTOM, 'd.M.Y H:m:i'); // Will return the foo date object as custom representation
Datatable::collection(User::all())
->addColumn($column)
->make();
$column = new FunctionColumn('foo', function ($row) { return strtolower($row->foo); }
Datatable::query(DB::table('table')->lists('foo'))
->showColumns('foo')
->addColumn($column)
->orderColumns('foo')
->searchColumns('foo')
->make()
$column = new FunctionColumn('user_id', function ($row) { return link_to('users/'.$row->user_id, $row->username) }
Datatable::query(DB::table('table')->lists('user_id', 'username'))
->showColumns('user_id')
->addColumn($column)
->orderColumns('user_id')
->searchColumns('user_id')
Datatable::from(DB::table("users")->select('firstname', "users.email as email2")->join('partners','users.partner_id','=','partners.id'))
->showColumns('firstname','email2')
->setSearchWithAlias()
->searchColumns("email2")
$table = Datatable::table()
->addColumn('Email2','Email', "Test")
->noScript();
// to render the table:
$table->render()
// later in the view you can render the javascript:
$table->script();
{{ DataTable::table()
->addColumn('ID', 'First Name', 'Last Name')
->setUrl($ajaxRouteToTableData)
->setOrder(array(2=>'asc', 1=>'asc')) // sort by last name then first name
->render('my.datatable.template') }}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.