+ Added new example about the new feature: custom column
This commit is contained in:
David
2025-03-17 22:33:11 -04:00
parent 096c7944b9
commit 25c6b316bd
14 changed files with 2260 additions and 7 deletions

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Livewire\Examples;
use App\Tables\TableWithCustomColumn;
use Livewire\Component;
class TableWithCustomColumnComponent extends Component
{
public function render()
{
return view('livewire.examples.custom-tables-component',[
'table' => TableWithCustomColumn::class
])->extends('components.layouts.app')
->section('content');
}
}

View File

@@ -3,8 +3,12 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Department extends Model class Department extends Model
{ {
// public function group() : BelongsTo
{
return $this->belongsTo(DepartmentGroup::class, 'id');
}
} }

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class DepartmentGroup extends Model
{
//
}

View File

@@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
class Product extends Model class Product extends Model
{ {
@@ -19,4 +20,9 @@ class Product extends Model
{ {
return $this->belongsTo(SubDepartment::class); return $this->belongsTo(SubDepartment::class);
} }
public function settings() : HasOne
{
return $this->hasOne(ProductSetting::class);
}
} }

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProductSetting extends Model
{
//
}

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Tables\Extensions;
use Closure;
use Mmt\GenericTable\Attributes\MappedRoute;
use Mmt\GenericTable\Components\Column;
use Mmt\GenericTable\Enums\ColumnSettingFlags;
use Mmt\GenericTable\Interfaces\IColumn;
use Mmt\GenericTable\Interfaces\IColumnFormatter;
use Mmt\GenericTable\Interfaces\IColumnRenderer;
use Str;
class IconColumn implements IColumn, IColumnRenderer
{
public int $settings = 0;
public string $bindedRoute = '';
public ?MappedRoute $mappedRoute = null;
public ?string $databaseColumnName = 'status';
public string $columnTitle = 'Status';
private Closure $setIconCallback;
public function __construct()
{
if($this->databaseColumnName == null)
$this->databaseColumnName = Str::snake($this->columnTitle);
}
public function renderCell(\Illuminate\Database\Eloquent\Model $rowModel): string
{
$icon = $this->setIconCallback->call($this, $rowModel);
return <<<HTML
<div class = "w-100 d-flex justify-content-start">
<i class = "$icon me-2"></i>
</div>
HTML;
}
public function route(MappedRoute $route)
{
$this->mappedRoute = $route;
return $this;
}
public function setIconIf(Closure $callback)
{
$this->setIconCallback = $callback;
return $this;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Tables;
use App\Models\Product;
use App\Tables\Extensions\IconColumn;
use Illuminate\Database\Eloquent\Model;
use Mmt\GenericTable\Components\Column;
use Mmt\GenericTable\Components\ColumnCollection;
use Mmt\GenericTable\Interfaces\IGenericTable;
class TableWithCustomColumn implements IGenericTable
{
public Model|string $model;
public ColumnCollection $columns;
public function __construct()
{
$this->model = new Product();
$this->columns = new ColumnCollection();
$icons = require_once('Extensions/bootstrap_icons.php');
$this->columns->add(new Column('Id'));
$this->columns->add(new Column('Name'));
$this->columns->add(new Column('Description'));
$this->columns->add(new IconColumn()->setIconIf(function(Model $rowModel) use($icons) {
if($rowModel->status == 'discontinued') {
return $icons['bag-check'] . ' text-success';
}
else {
return $icons['bag-x'] . ' text-danger';
}
}));
}
}

View File

@@ -10,11 +10,15 @@
"laravel/framework": "^11.31", "laravel/framework": "^11.31",
"laravel/tinker": "^2.9", "laravel/tinker": "^2.9",
"livewire/livewire": "^3.5", "livewire/livewire": "^3.5",
"maatwebsite/excel": "^3.1" "maatwebsite/excel": "^3.1",
"mmt/generic_table": "dev-main"
}, },
"repositories": [{ "repositories": [{
"type":"path", "type":"path",
"url": "packages/mmt/generic_table" "url": "packages/mmt/generic_table",
"options": {
"symlink": true
}
}], }],
"require-dev": { "require-dev": {
"barryvdh/laravel-debugbar": "^3.14", "barryvdh/laravel-debugbar": "^3.14",
@@ -74,6 +78,6 @@
"php-http/discovery": true "php-http/discovery": true
} }
}, },
"minimum-stability": "stable", "minimum-stability": "dev",
"prefer-stable": true "prefer-stable": true
} }

49
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "f01bce9daeec532ed6677dff2f53a64a", "content-hash": "cbca1116f23b7ddc2f9838738429a903",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@@ -2569,6 +2569,47 @@
}, },
"time": "2022-12-02T22:17:43+00:00" "time": "2022-12-02T22:17:43+00:00"
}, },
{
"name": "mmt/generic_table",
"version": "dev-main",
"dist": {
"type": "path",
"url": "packages/mmt/generic_table",
"reference": "bcc861502469bcad624f3b2c16ef482cca81825c"
},
"require": {
"illuminate/support": "^11.0",
"livewire/livewire": "^3.5",
"php": ">=8.4"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Mmt\\GenericTable\\ServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Mmt\\GenericTable\\": "src/"
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "David",
"email": "75149259+TitanDvd@users.noreply.github.com"
}
],
"description": "Generic table for Livewire + Laravel",
"transport-options": {
"symlink": true,
"relative": true
}
},
{ {
"name": "monolog/monolog", "name": "monolog/monolog",
"version": "3.8.1", "version": "3.8.1",
@@ -9835,8 +9876,10 @@
} }
], ],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "dev",
"stability-flags": {}, "stability-flags": {
"mmt/generic_table": 20
},
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {

View File

@@ -6,6 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title> <title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
</head> </head>
<body> <body>
<div class="container"> <div class="container">

View File

@@ -0,0 +1,3 @@
<div>
@generic_table($table)
</div>

View File

@@ -15,6 +15,7 @@
<li><a href="{{ route('with_drag_drop_ordering') }}">Drag and Drop Ordering</a></li> <li><a href="{{ route('with_drag_drop_ordering') }}">Drag and Drop Ordering</a></li>
<li><a href="{{ route('with_bulk_actions') }}">Bulk Actions</a></li> <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_relationships') }}">Relationships</a></li>
<li><a href="{{ route('with_custom_column') }}">Custom Column</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@@ -6,6 +6,7 @@ use App\Livewire\Examples\TableWithActionColumnComponent;
use App\Livewire\Examples\TableWithBindedRoutesComponent; use App\Livewire\Examples\TableWithBindedRoutesComponent;
use App\Livewire\Examples\TableWithBulkActionsComponent; use App\Livewire\Examples\TableWithBulkActionsComponent;
use App\Livewire\Examples\TableWithColumnFormatterComponent; use App\Livewire\Examples\TableWithColumnFormatterComponent;
use App\Livewire\Examples\TableWithCustomColumnComponent;
use App\Livewire\Examples\TableWithDragDropOrderingComponent; use App\Livewire\Examples\TableWithDragDropOrderingComponent;
use App\Livewire\Examples\TableWithExportComponent; use App\Livewire\Examples\TableWithExportComponent;
use App\Livewire\Examples\TableWithFiltersComponent; use App\Livewire\Examples\TableWithFiltersComponent;
@@ -27,6 +28,7 @@ Route::get('/with_pagination_settings', TableWithPaginationSettingsComponent::cl
Route::get('/with_drag_drop_ordering', TableWithDragDropOrderingComponent::class)->name('with_drag_drop_ordering'); Route::get('/with_drag_drop_ordering', TableWithDragDropOrderingComponent::class)->name('with_drag_drop_ordering');
Route::get('/with_bulk_actions', TableWithBulkActionsComponent::class)->name('with_bulk_actions'); Route::get('/with_bulk_actions', TableWithBulkActionsComponent::class)->name('with_bulk_actions');
Route::get('/with_relationships', TableWithRelationshipsComponent::class)->name('with_relationships'); Route::get('/with_relationships', TableWithRelationshipsComponent::class)->name('with_relationships');
Route::get('/with_custom_column', TableWithCustomColumnComponent::class)->name('with_custom_column');
Route::get('test', ParentComponent::class); Route::get('test', ParentComponent::class);