1. Go to this page and download the library: Download ivanharmat/crewgrid 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/ */
ivanharmat / crewgrid example snippets
namespace App\Livewire;
use App\Models\Order;
use CrewGrid\Columns\Column;
use CrewGrid\Grid;
use Illuminate\Contracts\Database\Eloquent\Builder;
class OrdersGrid extends Grid
{
protected function query(): Builder
{
return Order::query()->with('customer');
}
protected function columns(): array
{
return [
Column::make('Date', 'created_at')
->sortable()
->filterDateRange()
->format(fn ($value) => $value->format('M j, Y')),
Column::make('Customer', 'customer_id')
->filterMultiSelect(fn () => Customer::pluck('name', 'id')->all())
->format(fn ($value, $row) => e($row->customer?->name)),
Column::make('Reference', 'reference')
->sortable()
->searchable()
->filterText(),
Column::make('Total', 'total')
->sortable()
->format(fn ($value) => '$'.number_format($value, 2)),
Column::make('Actions', 'id')
->view('orders.grid-actions'), // gets $row and $value
];
}
}
protected function loadPreferences(): array
{
return auth()->user()->grid_preferences[$this->preferenceKey()] ?? [];
}
'remember_view' => true, // config: on for every grid
public ?bool $rememberView = false; // or off for one
public function mount(): void
{
parent::mount();
if ($this->sortField === '') {
$this->sortField = 'last_updated';
$this->sortDirection = 'desc';
}
}
public array $classes = ['button' => 'btn btn-danger btn-sm'];
$this->uiClass('action.danger'); // the theme's danger action button
$this->uiClass('action.warning'); // not shipped -> plain 'action', until you define it
'export' => true, // the button on every grid; a grid can override via public ?bool $exportable
'export_chunk' => 500, // rows read per query while streaming
protected function exportFilename(): string
{
return 'orders-'.date('Y-m-d').'.xlsx';
}