#FEAT
+ Added new example about the new feature: custom column
This commit is contained in:
17
app/Livewire/Examples/TableWithCustomColumnComponent.php
Normal file
17
app/Livewire/Examples/TableWithCustomColumnComponent.php
Normal 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');
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,12 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Department extends Model
|
||||
{
|
||||
//
|
||||
public function group() : BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DepartmentGroup::class, 'id');
|
||||
}
|
||||
}
|
||||
|
||||
10
app/Models/DepartmentGroup.php
Normal file
10
app/Models/DepartmentGroup.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DepartmentGroup extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
@@ -19,4 +20,9 @@ class Product extends Model
|
||||
{
|
||||
return $this->belongsTo(SubDepartment::class);
|
||||
}
|
||||
|
||||
public function settings() : HasOne
|
||||
{
|
||||
return $this->hasOne(ProductSetting::class);
|
||||
}
|
||||
}
|
||||
|
||||
10
app/Models/ProductSetting.php
Normal file
10
app/Models/ProductSetting.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductSetting extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
57
app/Tables/Extensions/IconColumn.php
Normal file
57
app/Tables/Extensions/IconColumn.php
Normal 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;
|
||||
}
|
||||
}
|
||||
2057
app/Tables/Extensions/bootstrap_icons.php
Normal file
2057
app/Tables/Extensions/bootstrap_icons.php
Normal file
File diff suppressed because it is too large
Load Diff
38
app/Tables/TableWithCustomColumn.php
Normal file
38
app/Tables/TableWithCustomColumn.php
Normal 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';
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,15 @@
|
||||
"laravel/framework": "^11.31",
|
||||
"laravel/tinker": "^2.9",
|
||||
"livewire/livewire": "^3.5",
|
||||
"maatwebsite/excel": "^3.1"
|
||||
"maatwebsite/excel": "^3.1",
|
||||
"mmt/generic_table": "dev-main"
|
||||
},
|
||||
"repositories": [{
|
||||
"type":"path",
|
||||
"url": "packages/mmt/generic_table"
|
||||
"url": "packages/mmt/generic_table",
|
||||
"options": {
|
||||
"symlink": true
|
||||
}
|
||||
}],
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-debugbar": "^3.14",
|
||||
@@ -74,6 +78,6 @@
|
||||
"php-http/discovery": true
|
||||
}
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
|
||||
49
composer.lock
generated
49
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "f01bce9daeec532ed6677dff2f53a64a",
|
||||
"content-hash": "cbca1116f23b7ddc2f9838738429a903",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
@@ -2569,6 +2569,47 @@
|
||||
},
|
||||
"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",
|
||||
"version": "3.8.1",
|
||||
@@ -9835,8 +9876,10 @@
|
||||
}
|
||||
],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {},
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": {
|
||||
"mmt/generic_table": 20
|
||||
},
|
||||
"prefer-stable": true,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<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 rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<div>
|
||||
@generic_table($table)
|
||||
</div>
|
||||
@@ -15,6 +15,7 @@
|
||||
<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_relationships') }}">Relationships</a></li>
|
||||
<li><a href="{{ route('with_custom_column') }}">Custom Column</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Livewire\Examples\TableWithActionColumnComponent;
|
||||
use App\Livewire\Examples\TableWithBindedRoutesComponent;
|
||||
use App\Livewire\Examples\TableWithBulkActionsComponent;
|
||||
use App\Livewire\Examples\TableWithColumnFormatterComponent;
|
||||
use App\Livewire\Examples\TableWithCustomColumnComponent;
|
||||
use App\Livewire\Examples\TableWithDragDropOrderingComponent;
|
||||
use App\Livewire\Examples\TableWithExportComponent;
|
||||
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_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('test', ParentComponent::class);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user