Fixing some examples

This commit is contained in:
David
2025-05-03 01:57:26 -04:00
parent 9f12bc28d0
commit d64e9c00be
13 changed files with 132 additions and 29 deletions

View File

@@ -5,38 +5,37 @@ namespace App\Tables;
use App\Models\Product;
use Mmt\GenericTable\Components\Column;
use Mmt\GenericTable\Components\ColumnCollection;
use Mmt\GenericTable\Enums\DatabaseEventQueryState;
use Mmt\GenericTable\Interfaces\IEvent;
use Mmt\GenericTable\Interfaces\IExportable;
use Mmt\GenericTable\Interfaces\IGenericTable;
use Mmt\GenericTable\Support\DatabaseEvent;
use Mmt\GenericTable\Support\GenericTableSettings;
class TableWithRelationships implements IGenericTable, IEvent
class TableWithRelationships implements IGenericTable, IExportable
{
public GenericTableSettings $tableSettings;
public function __construct()
{
$columns = new ColumnCollection()->add(
new Column('Name'),
new Column('Department'),
new Column('SubDepartment'),
$columns = ColumnCollection::make(
new Column('Product Name', 'name')
->searchable()
->sortable(),
new Column('Department Name', 'subDepartment.department.name')
->searchable()
->sortable(),
new Column('SubDepartment Name', 'subDepartment.name')
->searchable()
->exportable()
->sortable(),
);
$this->tableSettings = new GenericTableSettings(new Product(), $columns, true);
$this->tableSettings = new GenericTableSettings(new Product(), $columns);
}
public function dispatchCallback(\Mmt\GenericTable\Support\EventArgs $arguments): void
public function onExport(\Mmt\GenericTable\Support\ExportEventArgs $args): \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse
{
if($arguments instanceof DatabaseEvent) {
if($arguments->queryState == DatabaseEventQueryState::INITIALIZING) {
$arguments->builder->join('sub_departments', 'sub_departments.id', 'products.sub_department_id')
->join('departments', 'departments.id', 'sub_departments.department_id')
->select(
'products.name as name',
'departments.name as department',
'sub_departments.name as sub_department'
);
}
}
$args->query->take(5);
return $args->export();
}
}