diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d90ebbf --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Listen for Xdebug", + "type": "php", + "request": "launch", + "port": 9003, + "pathMappings": { + "C:\\xampp\\htdocs\\generic_table_examples": "${workspaceFolder}", + } + } + ] +} \ No newline at end of file diff --git a/app/Livewire/Examples/WithTwoTablesComponent.php b/app/Livewire/Examples/WithTwoTablesComponent.php index 5e38ee9..814fa4c 100644 --- a/app/Livewire/Examples/WithTwoTablesComponent.php +++ b/app/Livewire/Examples/WithTwoTablesComponent.php @@ -3,6 +3,7 @@ namespace App\Livewire\Examples; use App\Tables\DepartmentTable; +use App\Tables\SubDepartmentsTable; use App\Tables\TableWithDragDropOrdering; use Livewire\Component; @@ -12,9 +13,15 @@ class WithTwoTablesComponent extends Component { return view('livewire.examples.with-two-tables-component', [ 'products' => TableWithDragDropOrdering::class, - 'departments' => DepartmentTable::class + 'departments' => DepartmentTable::class, + 'subDepartments' => SubDepartmentsTable::class ]) ->extends('components.layouts.app') ->section('content'); } + + public function showModal() + { + $this->dispatch('showModal'); + } } diff --git a/app/Models/Department.php b/app/Models/Department.php index 2df8494..16a83a7 100644 --- a/app/Models/Department.php +++ b/app/Models/Department.php @@ -9,6 +9,6 @@ class Department extends Model { public function group() : BelongsTo { - return $this->belongsTo(DepartmentGroup::class, 'id'); + return $this->belongsTo(DepartmentGroup::class, 'department_group_id'); } } diff --git a/app/Tables/DepartmentTable.php b/app/Tables/DepartmentTable.php index c446f1b..a02bb56 100644 --- a/app/Tables/DepartmentTable.php +++ b/app/Tables/DepartmentTable.php @@ -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); } } \ No newline at end of file diff --git a/app/Tables/Extensions/IconColumn.php b/app/Tables/Extensions/IconColumn.php index d85ad50..f3732ad 100644 --- a/app/Tables/Extensions/IconColumn.php +++ b/app/Tables/Extensions/IconColumn.php @@ -55,4 +55,9 @@ class IconColumn implements IColumn, IColumnRenderer $this->setIconCallback = $callback; return $this; } + + public function isRelationship(): bool + { + return false; + } } \ No newline at end of file diff --git a/app/Tables/SubDepartmentsTable.php b/app/Tables/SubDepartmentsTable.php new file mode 100644 index 0000000..94ccc94 --- /dev/null +++ b/app/Tables/SubDepartmentsTable.php @@ -0,0 +1,26 @@ +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); + } +} \ No newline at end of file diff --git a/app/Tables/TableWithActionColumn.php b/app/Tables/TableWithActionColumn.php index ad47e2c..aef7ac9 100644 --- a/app/Tables/TableWithActionColumn.php +++ b/app/Tables/TableWithActionColumn.php @@ -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 { diff --git a/app/Tables/TableWithBindedRoutes.php b/app/Tables/TableWithBindedRoutes.php index 907ea3f..7b5851a 100644 --- a/app/Tables/TableWithBindedRoutes.php +++ b/app/Tables/TableWithBindedRoutes.php @@ -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( diff --git a/app/Tables/TableWithColumnFormatter.php b/app/Tables/TableWithColumnFormatter.php index fc7dfc5..426f8d5 100644 --- a/app/Tables/TableWithColumnFormatter.php +++ b/app/Tables/TableWithColumnFormatter.php @@ -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(); + } } \ No newline at end of file diff --git a/app/Tables/TableWithFilters.php b/app/Tables/TableWithFilters.php index 8f1f560..929a0a4 100644 --- a/app/Tables/TableWithFilters.php +++ b/app/Tables/TableWithFilters.php @@ -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( diff --git a/app/Tables/TableWithRelationships.php b/app/Tables/TableWithRelationships.php index 4bbb37a..8879296 100644 --- a/app/Tables/TableWithRelationships.php +++ b/app/Tables/TableWithRelationships.php @@ -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(); } } \ No newline at end of file diff --git a/resources/views/components/layouts/app.blade.php b/resources/views/components/layouts/app.blade.php index 4c32286..0e805ed 100644 --- a/resources/views/components/layouts/app.blade.php +++ b/resources/views/components/layouts/app.blade.php @@ -21,6 +21,8 @@ + + @yield('js') \ No newline at end of file diff --git a/resources/views/livewire/examples/with-two-tables-component.blade.php b/resources/views/livewire/examples/with-two-tables-component.blade.php index d80429f..4e89436 100644 --- a/resources/views/livewire/examples/with-two-tables-component.blade.php +++ b/resources/views/livewire/examples/with-two-tables-component.blade.php @@ -1,5 +1,27 @@
-
+ + + +
+
+ +
@@ -16,4 +38,19 @@
+ + {{-- @script --}} + + {{-- @endscript --}}
+ +@section('js') + +@endsection \ No newline at end of file