PHP code example of hafizhfadh / laravel-simple-datatable
1. Go to this page and download the library: Download hafizhfadh/laravel-simple-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/ */
hafizhfadh / laravel-simple-datatable example snippets
use HafizhFadh\LaravelSimpleDatatable\Facades\SimpleDatatable;
use HafizhFadh\LaravelSimpleDatatable\Support\Column;
use App\Models\User;
public function index()
{
// Automatically detects Builder and enables Server Mode
return SimpleDatatable::make(User::query())
->columns([
Column::make('name')->searchable()->sortable(),
Column::make('email')->searchable(),
Column::make('created_at')->sortable(),
])
->process();
}
use HafizhFadh\LaravelSimpleDatatable\Facades\SimpleDatatable;
use HafizhFadh\LaravelSimpleDatatable\Support\Column;
public function index()
{
$users = User::all(); // Returns a Collection
// Automatically detects Collection and enables Client Mode
return SimpleDatatable::make($users)
->columns([
Column::make('name')->searchable()->sortable(),
Column::make('email')->searchable(),
])
->process();
}
Column::make('username')
->searchable() // Allows filtering by this column
->sortable(); // Allows sorting by this column
SimpleDatatable::make(User::query())
->clientSide() // Force fetching all data and processing in memory
->process();