PHP code example of greystoneweb / livewire-datatables
1. Go to this page and download the library: Download greystoneweb/livewire-datatables 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/ */
greystoneweb / livewire-datatables example snippets
public function columns(): array
{
return [
Column::make('Name')
->sortable()
];
}
use Greystoneweb\LivewireDataTables\DataTable;
use Greystoneweb\LivewireDataTables\Traits\Exportable;
class UsersTable extends DataTable
{
// Use the Exportable trait
use Exportable;
// Define a fileName method that returns the filename
protected function fileName(): string
{
return 'users'.date('Y-m-d').'.csv';
}
...
}
use Greystoneweb\LivewireDataTables\DataTable;
use Greystoneweb\LivewireDataTables\Export;
use Greystoneweb\LivewireDataTables\Traits\Exportable;
class UsersTable extends DataTable
{
// Use the Exportable trait
use Exportable;
// Define a fileName method that returns the filename
protected function fileName(): string
{
return 'users'.date('Y-m-d').'.csv';
}
public function exporterInstance(): Export
{
return new UsersExport($this);
}
...
}
use Greystoneweb\LivewireDataTables\Export;
use Maatwebsite\Excel\Concerns\WithMapping;
class UsersExport extends Export implements WithMapping
{
public function headings(): array
{
return [
'Name',
'Organization',
'Email',
];
}
public function map($user): array
{
return [
$user->name,
$user->organization->name,
$user->email,
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.