Added an example with two tables in the same parent component
This commit is contained in:
20
app/Livewire/Examples/WithTwoTablesComponent.php
Normal file
20
app/Livewire/Examples/WithTwoTablesComponent.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Examples;
|
||||
|
||||
use App\Tables\DepartmentTable;
|
||||
use App\Tables\TableWithDragDropOrdering;
|
||||
use Livewire\Component;
|
||||
|
||||
class WithTwoTablesComponent extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.examples.with-two-tables-component', [
|
||||
'products' => TableWithDragDropOrdering::class,
|
||||
'departments' => DepartmentTable::class
|
||||
])
|
||||
->extends('components.layouts.app')
|
||||
->section('content');
|
||||
}
|
||||
}
|
||||
30
app/Tables/DepartmentTable.php
Normal file
30
app/Tables/DepartmentTable.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tables;
|
||||
|
||||
use App\Models\Department;
|
||||
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;
|
||||
|
||||
class DepartmentTable implements IGenericTable, IDragDropReordering
|
||||
{
|
||||
public Model|string $model = Department::class;
|
||||
|
||||
public ColumnCollection $columns;
|
||||
|
||||
public string $orderingColumn = 'order';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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());
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
<li><a href="{{ route('with_bulk_actions') }}">Bulk Actions</a></li>
|
||||
<li><a href="{{ route('with_relationships') }}">Relationships</a></li>
|
||||
<li><a href="{{ route('with_custom_column') }}">Custom Column</a></li>
|
||||
<li><a href="{{ route('many_tables') }}">Many Tables</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<div>
|
||||
<div class="row">
|
||||
<div class="col-8">
|
||||
@generic_table($products)
|
||||
</div>
|
||||
|
||||
<div class="col-4">
|
||||
@generic_table($departments)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user