From 63779f8bad4e09600486c35099e7dbd2f20a1b4e Mon Sep 17 00:00:00 2001 From: David <75149259+TitanDvd@users.noreply.github.com> Date: Mon, 31 Mar 2025 01:19:15 -0400 Subject: [PATCH] Added an example with two tables in the same parent component --- .../Examples/WithTwoTablesComponent.php | 20 +++++++++++++ app/Tables/DepartmentTable.php | 30 +++++++++++++++++++ app/Tables/TableWithDragDropOrdering.php | 30 +++++++++++++++---- .../examples/frame-component.blade.php | 1 + .../with-two-tables-component.blade.php | 11 +++++++ routes/web.php | 2 ++ 6 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 app/Livewire/Examples/WithTwoTablesComponent.php create mode 100644 app/Tables/DepartmentTable.php create mode 100644 resources/views/livewire/examples/with-two-tables-component.blade.php diff --git a/app/Livewire/Examples/WithTwoTablesComponent.php b/app/Livewire/Examples/WithTwoTablesComponent.php new file mode 100644 index 0000000..5e38ee9 --- /dev/null +++ b/app/Livewire/Examples/WithTwoTablesComponent.php @@ -0,0 +1,20 @@ + TableWithDragDropOrdering::class, + 'departments' => DepartmentTable::class + ]) + ->extends('components.layouts.app') + ->section('content'); + } +} diff --git a/app/Tables/DepartmentTable.php b/app/Tables/DepartmentTable.php new file mode 100644 index 0000000..8cfd5ab --- /dev/null +++ b/app/Tables/DepartmentTable.php @@ -0,0 +1,30 @@ +columns = new ColumnCollection(); + $this->columns->add(new Column("Id")); + $this->columns->add(new Column("Name")); + $this->columns->add(new Column("Tags")); + $this->columns->add(new Column("Status")); + $this->columns->add(new Column("Order")->sortable()->defaultSortDesc()); + } +} \ No newline at end of file diff --git a/app/Tables/TableWithDragDropOrdering.php b/app/Tables/TableWithDragDropOrdering.php index 26d31f6..a101ea4 100644 --- a/app/Tables/TableWithDragDropOrdering.php +++ b/app/Tables/TableWithDragDropOrdering.php @@ -5,16 +5,36 @@ namespace App\Tables; use App\Models\Product; use App\Tables\Traits\WithColumnFormatter; use Illuminate\Database\Eloquent\Model; +use Mmt\GenericTable\Components\Column; +use Mmt\GenericTable\Components\ColumnCollection; +use Mmt\GenericTable\Enums\ColumnSettingFlags; use Mmt\GenericTable\Interfaces\IDragDropReordering; use Mmt\GenericTable\Interfaces\IGenericTable; +use Mmt\GenericTable\Interfaces\ISingleSelectionFilter; +use Mmt\GenericTable\Support\SelectionFilterSettings; -class TableWithDragDropOrdering implements IGenericTable, IDragDropReordering +class TableWithDragDropOrdering implements IGenericTable, IDragDropReordering, ISingleSelectionFilter { - use WithColumnFormatter; - - public string $Order; - public Model|string $model = Product::class; + public ColumnCollection $columns; + public string $orderingColumn = 'order'; + + public SelectionFilterSettings $singleSelectionFilterSettings; + + public function __construct() + { + $this->columns = ColumnCollection::make( + new Column('Id'), + new Column('Name'), + new Column('Description'), + new Column('Price'), + new Column('Stock'), + new Column('Order')->withSettings(ColumnSettingFlags::DEFAULT_SORT_DESC) + ); + + $this->singleSelectionFilterSettings = new SelectionFilterSettings('name'); + $this->singleSelectionFilterSettings->add('Make pop', 'ml'); + } } \ No newline at end of file diff --git a/resources/views/livewire/examples/frame-component.blade.php b/resources/views/livewire/examples/frame-component.blade.php index 8f929be..57b1210 100644 --- a/resources/views/livewire/examples/frame-component.blade.php +++ b/resources/views/livewire/examples/frame-component.blade.php @@ -16,6 +16,7 @@
  • Bulk Actions
  • Relationships
  • Custom Column
  • +
  • Many Tables
  • diff --git a/resources/views/livewire/examples/with-two-tables-component.blade.php b/resources/views/livewire/examples/with-two-tables-component.blade.php new file mode 100644 index 0000000..2a2afd0 --- /dev/null +++ b/resources/views/livewire/examples/with-two-tables-component.blade.php @@ -0,0 +1,11 @@ +
    +
    +
    + @generic_table($products) +
    + +
    + @generic_table($departments) +
    +
    +
    diff --git a/routes/web.php b/routes/web.php index 996a5b1..2adc67e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,6 +13,7 @@ use App\Livewire\Examples\TableWithFiltersComponent; use App\Livewire\Examples\TableWithNoSettingsComponent; use App\Livewire\Examples\TableWithPaginationSettingsComponent; use App\Livewire\Examples\TableWithRelationshipsComponent; +use App\Livewire\Examples\WithTwoTablesComponent; use App\Livewire\Test\ParentComponent; use Illuminate\Support\Facades\Route; @@ -29,6 +30,7 @@ Route::get('/with_drag_drop_ordering', TableWithDragDropOrderingComponent::class Route::get('/with_bulk_actions', TableWithBulkActionsComponent::class)->name('with_bulk_actions'); Route::get('/with_relationships', TableWithRelationshipsComponent::class)->name('with_relationships'); Route::get('/with_custom_column', TableWithCustomColumnComponent::class)->name('with_custom_column'); +Route::get('/many_tables', WithTwoTablesComponent::class)->name('many_tables'); Route::get('test', ParentComponent::class);