Fixing some examples
This commit is contained in:
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
@@ -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}",
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -55,4 +55,9 @@ class IconColumn implements IColumn, IColumnRenderer
|
||||
$this->setIconCallback = $callback;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isRelationship(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
26
app/Tables/SubDepartmentsTable.php
Normal file
26
app/Tables/SubDepartmentsTable.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
||||
@yield('js')
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +1,27 @@
|
||||
<div>
|
||||
<div class="row">
|
||||
<div class="modal fade" tabindex="-1" id = "subDepartments" wire:ignore.self>
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Sub Departamentos</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@generic_table($subDepartments)
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary">Save changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-12">
|
||||
<button class="btn btn-primary" wire:click = "showModal">See sub departments</button>
|
||||
</div>
|
||||
<div class="col-7">
|
||||
<div class="card">
|
||||
<div class="card-body p-0">
|
||||
@@ -16,4 +38,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- @script --}}
|
||||
|
||||
{{-- @endscript --}}
|
||||
</div>
|
||||
|
||||
@section('js')
|
||||
<script>
|
||||
document.addEventListener('livewire:initialized', () => {
|
||||
@this.on('showModal', () => {
|
||||
const myModal = new bootstrap.Modal('#subDepartments');
|
||||
myModal.show();
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endsection
|
||||
Reference in New Issue
Block a user