1. Go to this page and download the library: Download zk/laravel-datagrid 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/ */
zk / laravel-datagrid example snippets
use Zk\DataGrid\DataGrid;
use App\Models\Post;
class PostGrid extends DataGrid {
public function prepareItems(): void
{
$this->fromQuery(Post::query());
}
public function prepareColumns(): void
{
// Serial No
$this->addColumn([
'title' => '#',
'column' => '',
'type' => 'serial-no',
]);
// Title
$this->addColumn([
'column' => 'title',
'type' => 'string',
'sortable' => true,
'filterable' => true,
'searchable' => true,
]);
// Status
$this->addColumn([
'column' => 'status',
'type' => 'number',
'sortable' => true,
'formatter' => fn($item) => $item->status ? 'Active' : 'Inactive',
]);
}
}