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

@@ -2,7 +2,7 @@
namespace App\Tables;
use App\Models\Product;
use App\Models\Department;
use Mmt\GenericTable\Components\Column;
use Mmt\GenericTable\Components\ColumnCollection;
use Mmt\GenericTable\Interfaces\IDragDropReordering;
@@ -24,6 +24,6 @@ class DepartmentTable implements IGenericTable, IDragDropReordering
$columns->add(new Column("Status"));
$columns->add(new Column("Order")->sortable()->defaultSortDesc());
$this->tableSettings = new GenericTableSettings(new Product(), $columns);
$this->tableSettings = new GenericTableSettings(new Department(), $columns);
}
}

View File

@@ -55,4 +55,9 @@ class IconColumn implements IColumn, IColumnRenderer
$this->setIconCallback = $callback;
return $this;
}
public function isRelationship(): bool
{
return false;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Tables;
use App\Models\SubDepartment;
use Mmt\GenericTable\Components\Column;
use Mmt\GenericTable\Components\ColumnCollection;
use Mmt\GenericTable\Interfaces\IDragDropReordering;
use Mmt\GenericTable\Interfaces\IGenericTable;
use Mmt\GenericTable\Support\GenericTableSettings;
class SubDepartmentsTable implements IGenericTable
{
public GenericTableSettings $tableSettings;
public function __construct()
{
$columns = new ColumnCollection();
$columns->add(new Column("Id", 'id as uid'));
$columns->add(new Column("Sub Department Name", 'name'));
$columns->add(new Column("Status"));
$columns->add(new Column("Department Name", 'department.name'));
$this->tableSettings = new GenericTableSettings(new SubDepartment(), $columns);
}
}

View File

@@ -12,7 +12,7 @@ class TableWithActionColumn implements IGenericTable, IActionColumn
{
use WithExportableProductColumns;
public int $actionColumnIndex = 0;
public int $actionColumnIndex = 2;
public function actionView(IRowData $row): \Illuminate\View\View
{

View File

@@ -26,6 +26,7 @@ class TableWithBindedRoutes implements IGenericTable, IDragDropReordering
new Column('Price'),
new Column('Stock'),
new Column('SubDepartment', 'subDepartment.name'),
new Column('Order')->hide()
);
$this->tableSettings = new GenericTableSettings(

View File

@@ -3,9 +3,17 @@
namespace App\Tables;
use App\Tables\Traits\WithColumnFormatter;
use Mmt\GenericTable\Interfaces\IExportable;
use Mmt\GenericTable\Interfaces\IGenericTable;
class TableWithColumnFormatter implements IGenericTable
class TableWithColumnFormatter implements IGenericTable, IExportable
{
use WithColumnFormatter;
public function onExport(\Mmt\GenericTable\Support\ExportEventArgs $args): \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse
{
$args->useStripTags = true;
$args->query->take(5);
return $args->export();
}
}

View File

@@ -44,7 +44,8 @@ class TableWithFilters implements IGenericTable, IEvent, IDateRangeFilter, IColu
new Column('Id')->hookFormatter(fn(IRowData $row) => '#'.$row->get('id')),
new Column('Order')->sortable()->defaultSort(),
new Column('Name'),
new Column('Price')
new Column('Price'),
new Column('Status')->hide()
);
$this->filters = new FilterCollection(

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();
}
}