Refactor table components to use GenericTableSettings and remove deprecated classes
This commit is contained in:
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Livewire\Examples;
|
|
||||||
|
|
||||||
use App\Tables\TableWithMySettings;
|
|
||||||
use Livewire\Component;
|
|
||||||
|
|
||||||
class MyCustomSettingsTableComponent extends Component
|
|
||||||
{
|
|
||||||
public function render()
|
|
||||||
{
|
|
||||||
return view('livewire.examples.my-custom-settings-table-component', [
|
|
||||||
'table' => TableWithMySettings::class
|
|
||||||
])
|
|
||||||
->extends('components.layouts.app')
|
|
||||||
->section('content');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,29 +2,28 @@
|
|||||||
|
|
||||||
namespace App\Tables;
|
namespace App\Tables;
|
||||||
|
|
||||||
use App\Models\Department;
|
use App\Models\Product;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Mmt\GenericTable\Components\Column;
|
use Mmt\GenericTable\Components\Column;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
use Mmt\GenericTable\Enums\ColumnSettingFlags;
|
|
||||||
use Mmt\GenericTable\Interfaces\IDragDropReordering;
|
use Mmt\GenericTable\Interfaces\IDragDropReordering;
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||||
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
|
|
||||||
class DepartmentTable implements IGenericTable, IDragDropReordering
|
class DepartmentTable implements IGenericTable, IDragDropReordering
|
||||||
{
|
{
|
||||||
public Model|string $model = Department::class;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
public ColumnCollection $columns;
|
|
||||||
|
|
||||||
public string $orderingColumn = 'order';
|
public string $orderingColumn = 'order';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->columns = new ColumnCollection();
|
$columns = new ColumnCollection();
|
||||||
$this->columns->add(new Column("Id"));
|
$columns->add(new Column("Id"));
|
||||||
$this->columns->add(new Column("Name"));
|
$columns->add(new Column("Name"));
|
||||||
$this->columns->add(new Column("Tags"));
|
$columns->add(new Column("Tags"));
|
||||||
$this->columns->add(new Column("Status"));
|
$columns->add(new Column("Status"));
|
||||||
$this->columns->add(new Column("Order")->sortable()->defaultSortDesc());
|
$columns->add(new Column("Order")->sortable()->defaultSortDesc());
|
||||||
|
|
||||||
|
$this->tableSettings = new GenericTableSettings(new Product(), $columns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,10 @@ namespace App\Tables\Extensions;
|
|||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Mmt\GenericTable\Attributes\MappedRoute;
|
use Mmt\GenericTable\Attributes\MappedRoute;
|
||||||
|
use Mmt\GenericTable\Interfaces\ICellData;
|
||||||
use Mmt\GenericTable\Interfaces\IColumn;
|
use Mmt\GenericTable\Interfaces\IColumn;
|
||||||
use Mmt\GenericTable\Interfaces\IColumnRenderer;
|
use Mmt\GenericTable\Interfaces\IColumnRenderer;
|
||||||
|
use Mmt\GenericTable\Interfaces\IRowData;
|
||||||
use Str;
|
use Str;
|
||||||
|
|
||||||
class IconColumn implements IColumn, IColumnRenderer
|
class IconColumn implements IColumn, IColumnRenderer
|
||||||
@@ -20,17 +22,19 @@ class IconColumn implements IColumn, IColumnRenderer
|
|||||||
|
|
||||||
private Closure $setIconCallback;
|
private Closure $setIconCallback;
|
||||||
|
|
||||||
|
public int $columnIndex;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
if($this->databaseColumnName == null)
|
if($this->databaseColumnName == null)
|
||||||
$this->databaseColumnName = Str::snake($this->columnTitle);
|
$this->databaseColumnName = Str::snake($this->columnTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderCell(\Illuminate\Database\Eloquent\Model $rowModel): string
|
public function renderCell(ICellData $cell, IRowData $row): string|null
|
||||||
{
|
{
|
||||||
$icon = 'bi bi-arrow-up-right-circle-fill';
|
$icon = 'bi bi-arrow-up-right-circle-fill';
|
||||||
if(isset($this->setIconCallback))
|
if(isset($this->setIconCallback))
|
||||||
$icon = $this->setIconCallback->call($this, $rowModel);
|
$icon = $this->setIconCallback->call($this, $row);
|
||||||
|
|
||||||
return <<<HTML
|
return <<<HTML
|
||||||
<div class = "w-100 d-flex justify-content-start">
|
<div class = "w-100 d-flex justify-content-start">
|
||||||
|
|||||||
@@ -3,30 +3,19 @@
|
|||||||
namespace App\Tables;
|
namespace App\Tables;
|
||||||
|
|
||||||
|
|
||||||
use App\Models\Product;
|
|
||||||
use App\Tables\Traits\WithExportableProductColumns;
|
use App\Tables\Traits\WithExportableProductColumns;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Mmt\GenericTable\Interfaces\IActionColumn;
|
use Mmt\GenericTable\Interfaces\IActionColumn;
|
||||||
use Mmt\GenericTable\Interfaces\IEvent;
|
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||||
use Mmt\GenericTable\Support\EventArgs;
|
use Mmt\GenericTable\Interfaces\IRowData;
|
||||||
|
|
||||||
class TableWithActionColumn implements IGenericTable, IActionColumn, IEvent
|
class TableWithActionColumn implements IGenericTable, IActionColumn
|
||||||
{
|
{
|
||||||
use WithExportableProductColumns;
|
use WithExportableProductColumns;
|
||||||
|
|
||||||
public Model|string $model = Product::class;
|
|
||||||
|
|
||||||
public int $actionColumnIndex = 0;
|
public int $actionColumnIndex = 0;
|
||||||
|
|
||||||
public function actionView(Model $item): \Illuminate\View\View
|
public function actionView(IRowData $row): \Illuminate\View\View
|
||||||
{
|
{
|
||||||
return view("tables_action_views.edit_delete_details", ['productId' => $item->id]);
|
return view("tables_action_views.edit_delete_details", ['productId' => $row->get('name')]);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function dispatchCallback(EventArgs $arguments): void
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,22 +2,23 @@
|
|||||||
|
|
||||||
namespace App\Tables;
|
namespace App\Tables;
|
||||||
|
|
||||||
use App\Tables\Traits\WithColumnFormatter;
|
use App\Models\Product;
|
||||||
use Mmt\GenericTable\Attributes\MappedRoute;
|
use Mmt\GenericTable\Attributes\MappedRoute;
|
||||||
use Mmt\GenericTable\Components\Column;
|
use Mmt\GenericTable\Components\Column;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
use Mmt\GenericTable\Interfaces\IDragDropReordering;
|
use Mmt\GenericTable\Interfaces\IDragDropReordering;
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||||
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
|
|
||||||
class TableWithBindedRoutes implements IGenericTable, IDragDropReordering
|
class TableWithBindedRoutes implements IGenericTable, IDragDropReordering
|
||||||
{
|
{
|
||||||
use WithColumnFormatter;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
public string $orderingColumn;
|
public string $orderingColumn;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->columns = ColumnCollection::make(
|
$columns = ColumnCollection::make(
|
||||||
new Column('Id'),
|
new Column('Id'),
|
||||||
new Column('Name'),
|
new Column('Name'),
|
||||||
new Column('Description')
|
new Column('Description')
|
||||||
@@ -26,5 +27,9 @@ class TableWithBindedRoutes implements IGenericTable, IDragDropReordering
|
|||||||
new Column('Stock'),
|
new Column('Stock'),
|
||||||
new Column('SubDepartment', 'subDepartment.name'),
|
new Column('SubDepartment', 'subDepartment.name'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->tableSettings = new GenericTableSettings(
|
||||||
|
Product::class, $columns
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Tables;
|
namespace App\Tables;
|
||||||
|
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Mmt\GenericTable\Components\Column;
|
use Mmt\GenericTable\Components\Column;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
use Mmt\GenericTable\Interfaces\IBulkAction;
|
use Mmt\GenericTable\Interfaces\IBulkAction;
|
||||||
@@ -12,20 +11,17 @@ use Mmt\GenericTable\Support\BulkAction;
|
|||||||
use Mmt\GenericTable\Support\BulkActionCollection;
|
use Mmt\GenericTable\Support\BulkActionCollection;
|
||||||
use Mmt\GenericTable\Support\BulkActionGroup;
|
use Mmt\GenericTable\Support\BulkActionGroup;
|
||||||
use Mmt\GenericTable\Support\BulkActionSettings;
|
use Mmt\GenericTable\Support\BulkActionSettings;
|
||||||
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
|
|
||||||
class TableWithBulkActions implements IGenericTable, IBulkAction
|
class TableWithBulkActions implements IGenericTable, IBulkAction
|
||||||
{
|
{
|
||||||
public Model|string $model;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
public ColumnCollection $columns;
|
|
||||||
|
|
||||||
public BulkActionCollection $bulkActionCollection;
|
public BulkActionCollection $bulkActionCollection;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->model = new Product();
|
$columns = ColumnCollection::make(
|
||||||
|
|
||||||
$this->columns = ColumnCollection::make(
|
|
||||||
new Column('Id'),
|
new Column('Id'),
|
||||||
new Column('Description'),
|
new Column('Description'),
|
||||||
new Column('Price'),
|
new Column('Price'),
|
||||||
@@ -48,6 +44,8 @@ class TableWithBulkActions implements IGenericTable, IBulkAction
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->tableSettings = new GenericTableSettings(Product::class, $columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,35 +4,35 @@ namespace App\Tables;
|
|||||||
|
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Tables\Extensions\IconColumn;
|
use App\Tables\Extensions\IconColumn;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Mmt\GenericTable\Components\Column;
|
use Mmt\GenericTable\Components\Column;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||||
|
use Mmt\GenericTable\Interfaces\IRowData;
|
||||||
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
|
|
||||||
class TableWithCustomColumn implements IGenericTable
|
class TableWithCustomColumn implements IGenericTable
|
||||||
{
|
{
|
||||||
public Model|string $model;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
public ColumnCollection $columns;
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->model = new Product();
|
|
||||||
$this->columns = new ColumnCollection();
|
|
||||||
|
|
||||||
$icons = require_once('Extensions/bootstrap_icons.php');
|
$icons = require_once('Extensions/bootstrap_icons.php');
|
||||||
|
|
||||||
$this->columns->add(new Column('Id'));
|
$columns = new ColumnCollection();
|
||||||
$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') {
|
$columns->add(new Column('Id'));
|
||||||
|
$columns->add(new Column('Name'));
|
||||||
|
$columns->add(new Column('Description'));
|
||||||
|
$columns->add(new IconColumn()->setIconIf(function(IRowData $rowModel) use($icons) {
|
||||||
|
|
||||||
|
if($rowModel->get('status') == 'discontinued') {
|
||||||
return $icons['bag-check'] . ' text-success';
|
return $icons['bag-check'] . ' text-success';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return $icons['bag-x'] . ' text-danger';
|
return $icons['bag-x'] . ' text-danger';
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
$this->tableSettings = new GenericTableSettings(new Product(), $columns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,29 +3,29 @@
|
|||||||
namespace App\Tables;
|
namespace App\Tables;
|
||||||
|
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Tables\Traits\WithColumnFormatter;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Mmt\GenericTable\Components\Column;
|
use Mmt\GenericTable\Components\Column;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
use Mmt\GenericTable\Enums\ColumnSettingFlags;
|
use Mmt\GenericTable\Enums\ColumnSettingFlags;
|
||||||
|
use Mmt\GenericTable\Interfaces\IColumnFilter;
|
||||||
use Mmt\GenericTable\Interfaces\IDragDropReordering;
|
use Mmt\GenericTable\Interfaces\IDragDropReordering;
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||||
use Mmt\GenericTable\Interfaces\ISingleSelectionFilter;
|
use Mmt\GenericTable\Support\FilterCollection;
|
||||||
use Mmt\GenericTable\Support\SelectionFilterSettings;
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
|
use Mmt\GenericTable\Support\SingleFilter;
|
||||||
|
|
||||||
class TableWithDragDropOrdering implements IGenericTable, IDragDropReordering, ISingleSelectionFilter
|
class TableWithDragDropOrdering implements IGenericTable, IDragDropReordering, IColumnFilter
|
||||||
{
|
{
|
||||||
public Model|string $model = Product::class;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
public ColumnCollection $columns;
|
|
||||||
|
|
||||||
public string $orderingColumn = 'order';
|
public string $orderingColumn = 'order';
|
||||||
|
|
||||||
public SelectionFilterSettings $singleSelectionFilterSettings;
|
public FilterCollection $filters;
|
||||||
|
|
||||||
|
public bool $useBuilder;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->columns = ColumnCollection::make(
|
$columns = ColumnCollection::make(
|
||||||
new Column('Id'),
|
new Column('Id'),
|
||||||
new Column('Name'),
|
new Column('Name'),
|
||||||
new Column('Description'),
|
new Column('Description'),
|
||||||
@@ -34,7 +34,13 @@ class TableWithDragDropOrdering implements IGenericTable, IDragDropReordering, I
|
|||||||
new Column('Order')->withSettings(ColumnSettingFlags::DEFAULT_SORT_DESC)
|
new Column('Order')->withSettings(ColumnSettingFlags::DEFAULT_SORT_DESC)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->singleSelectionFilterSettings = new SelectionFilterSettings('name');
|
$this->tableSettings = new GenericTableSettings(Product::class, $columns);
|
||||||
$this->singleSelectionFilterSettings->add('Make pop', 'ml');
|
|
||||||
|
$this->filters = new FilterCollection(
|
||||||
|
SingleFilter::make('name', [
|
||||||
|
'Yes' => 'yes',
|
||||||
|
'No' => 'No',
|
||||||
|
])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,32 +3,55 @@
|
|||||||
namespace App\Tables;
|
namespace App\Tables;
|
||||||
|
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Tables\Traits\WithExportableProductColumns;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Mmt\GenericTable\Attributes\CellFormatter;
|
use Mmt\GenericTable\Attributes\CellFormatter;
|
||||||
|
use Mmt\GenericTable\Components\Cell;
|
||||||
|
use Mmt\GenericTable\Components\Column;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
|
use Mmt\GenericTable\Enums\ColumnSettingFlags;
|
||||||
use Mmt\GenericTable\Interfaces\IExportable;
|
use Mmt\GenericTable\Interfaces\IExportable;
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||||
use Mmt\GenericTable\Support\ExportEventArgs;
|
use Mmt\GenericTable\Support\ExportEventArgs;
|
||||||
use Mmt\GenericTable\Support\ExportSettings;
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||||
|
|
||||||
class TableWithExport implements IGenericTable, IExportable
|
class TableWithExport implements IGenericTable, IExportable
|
||||||
{
|
{
|
||||||
use WithExportableProductColumns;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$columns = ColumnCollection::make(
|
||||||
|
new Column('Name')->withSettings(ColumnSettingFlags::EXPORTABLE),
|
||||||
|
new Column('Description')->withSettings(ColumnSettingFlags::EXPORTABLE),
|
||||||
|
new Column('Price')->withSettings(ColumnSettingFlags::EXPORTABLE),
|
||||||
|
new Column('Stock')->withSettings(ColumnSettingFlags::EXPORTABLE)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->tableSettings = new GenericTableSettings(
|
||||||
|
Product::class,
|
||||||
|
$columns
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function onExport(ExportEventArgs $args) : BinaryFileResponse|Response
|
public function onExport(ExportEventArgs $args) : BinaryFileResponse|Response
|
||||||
{
|
{
|
||||||
$args->query->take(5);
|
$args->query->take(5);
|
||||||
$args->settings->useFormatters = true;
|
$args->settings->useFormatters = true;
|
||||||
$args->settings->fileName = 'products';
|
$args->settings->fileName = 'products';
|
||||||
|
$args->useStripTags = true;
|
||||||
return $args->export();
|
return $args->export();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[CellFormatter('price')]
|
#[CellFormatter('price')]
|
||||||
public function priceFormatter($rowModel)
|
public function priceFormatter(Cell $cell)
|
||||||
{
|
{
|
||||||
return '$'.$rowModel->price;
|
return '$'.$cell->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[CellFormatter('name')]
|
||||||
|
public function nameFormatter(Cell $cell)
|
||||||
|
{
|
||||||
|
return '<i>La</i> ' . $cell->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,6 @@ namespace App\Tables;
|
|||||||
|
|
||||||
|
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Mmt\GenericTable\Components\Column;
|
use Mmt\GenericTable\Components\Column;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
use Mmt\GenericTable\Enums\CommonDateFilter;
|
use Mmt\GenericTable\Enums\CommonDateFilter;
|
||||||
@@ -14,21 +13,18 @@ use Mmt\GenericTable\Interfaces\IDragDropReordering;
|
|||||||
use Mmt\GenericTable\Interfaces\IEvent;
|
use Mmt\GenericTable\Interfaces\IEvent;
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||||
use Mmt\GenericTable\Interfaces\ILoadingIndicator;
|
use Mmt\GenericTable\Interfaces\ILoadingIndicator;
|
||||||
use Mmt\GenericTable\Interfaces\IMultiSelectionFilter;
|
use Mmt\GenericTable\Interfaces\IRowData;
|
||||||
use Mmt\GenericTable\Interfaces\ISingleSelectionFilter;
|
|
||||||
use Mmt\GenericTable\Support\DatabaseEvent;
|
use Mmt\GenericTable\Support\DatabaseEvent;
|
||||||
use Mmt\GenericTable\Support\DateFilterSettings;
|
use Mmt\GenericTable\Support\DateFilterSettings;
|
||||||
use Mmt\GenericTable\Support\EventArgs;
|
use Mmt\GenericTable\Support\EventArgs;
|
||||||
use Mmt\GenericTable\Support\FilterCollection;
|
use Mmt\GenericTable\Support\FilterCollection;
|
||||||
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
use Mmt\GenericTable\Support\MultiFilter;
|
use Mmt\GenericTable\Support\MultiFilter;
|
||||||
use Mmt\GenericTable\Support\SelectionFilterSettings;
|
|
||||||
use Mmt\GenericTable\Support\SingleFilter;
|
use Mmt\GenericTable\Support\SingleFilter;
|
||||||
|
|
||||||
class TableWithFilters implements IGenericTable, IEvent, IDateRangeFilter, IColumnFilter, IDragDropReordering, ILoadingIndicator
|
class TableWithFilters implements IGenericTable, IEvent, IDateRangeFilter, IColumnFilter, IDragDropReordering, ILoadingIndicator
|
||||||
{
|
{
|
||||||
public Model|string $model = Product::class;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
public ColumnCollection $columns;
|
|
||||||
|
|
||||||
public DateFilterSettings $dateFilterSettings;
|
public DateFilterSettings $dateFilterSettings;
|
||||||
|
|
||||||
@@ -44,8 +40,8 @@ class TableWithFilters implements IGenericTable, IEvent, IDateRangeFilter, IColu
|
|||||||
CommonDateFilter::LAST_3_MONTHS
|
CommonDateFilter::LAST_3_MONTHS
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->columns = ColumnCollection::make(
|
$columns = ColumnCollection::make(
|
||||||
new Column('Id')->hookFormatter(fn($row) => '#'.$row->id),
|
new Column('Id')->hookFormatter(fn(IRowData $row) => '#'.$row->get('id')),
|
||||||
new Column('Order')->sortable()->defaultSort(),
|
new Column('Order')->sortable()->defaultSort(),
|
||||||
new Column('Name'),
|
new Column('Name'),
|
||||||
new Column('Price')
|
new Column('Price')
|
||||||
@@ -65,6 +61,10 @@ class TableWithFilters implements IGenericTable, IEvent, IDateRangeFilter, IColu
|
|||||||
'Client-3' => 'rem 61603388',
|
'Client-3' => 'rem 61603388',
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->tableSettings = new GenericTableSettings(
|
||||||
|
Product::class, $columns
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Tables;
|
|
||||||
|
|
||||||
use App\Models\Product;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Support\Facades\Date;
|
|
||||||
use Mmt\GenericTable\Attributes\BulkAction;
|
|
||||||
use Mmt\GenericTable\Attributes\Column;
|
|
||||||
use Mmt\GenericTable\Attributes\ColumnFilter;
|
|
||||||
use Mmt\GenericTable\Attributes\ColumnSettings;
|
|
||||||
use Mmt\GenericTable\Attributes\MappedColumn;
|
|
||||||
use Mmt\GenericTable\Enums\ColumnSettingFlags;
|
|
||||||
use Mmt\GenericTable\Enums\CommonDateFilter;
|
|
||||||
use Mmt\GenericTable\Enums\FilterType;
|
|
||||||
use Mmt\GenericTable\Interfaces\IDateRangeFilter;
|
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
|
||||||
use Mmt\GenericTable\Support\DateFilterSettings;
|
|
||||||
|
|
||||||
class TableWithMySettings implements IGenericTable
|
|
||||||
{
|
|
||||||
public Model|string $model = Product::class;
|
|
||||||
|
|
||||||
public DateFilterSettings $dateRanges;
|
|
||||||
|
|
||||||
#[MappedColumn]
|
|
||||||
public int $Id;
|
|
||||||
|
|
||||||
|
|
||||||
#[MappedColumn]
|
|
||||||
public string $Name;
|
|
||||||
|
|
||||||
|
|
||||||
#[MappedColumn('subDepartment.department.name')]
|
|
||||||
public string $Department;
|
|
||||||
|
|
||||||
|
|
||||||
#[MappedColumn]
|
|
||||||
public string $CreatedAt;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// #[ColumnFilter('created_at', FilterType::DATE_RANGE)]
|
|
||||||
// public function sijsjm()
|
|
||||||
// {
|
|
||||||
// return setFlags(
|
|
||||||
// CommonDateFilter::LAST_3_MONTHS,
|
|
||||||
// CommonDateFilter::LAST_3_MONTHS,
|
|
||||||
// CommonDateFilter::LAST_3_MONTHS
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Tables;
|
namespace App\Tables;
|
||||||
|
|
||||||
use App\Models\Product;
|
|
||||||
use App\Tables\Traits\WithColumnFormatter;
|
use App\Tables\Traits\WithColumnFormatter;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Mmt\GenericTable\Enums\PaginationRack;
|
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||||
use Mmt\GenericTable\Interfaces\IPaginationRack;
|
use Mmt\GenericTable\Interfaces\IPaginationRack;
|
||||||
use Mmt\GenericTable\Interfaces\IRowsPerPage;
|
use Mmt\GenericTable\Interfaces\IRowsPerPage;
|
||||||
@@ -13,17 +10,4 @@ use Mmt\GenericTable\Interfaces\IRowsPerPage;
|
|||||||
class TableWithPaginationSettings implements IGenericTable, IPaginationRack, IRowsPerPage
|
class TableWithPaginationSettings implements IGenericTable, IPaginationRack, IRowsPerPage
|
||||||
{
|
{
|
||||||
use WithColumnFormatter;
|
use WithColumnFormatter;
|
||||||
|
|
||||||
public Model|string $model = Product::class;
|
|
||||||
|
|
||||||
public int $paginationRack = 0;
|
|
||||||
|
|
||||||
public int $rowsPerPage = 10;
|
|
||||||
|
|
||||||
public array $rowsPerPageOptions = [10,20,40,60,80];
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
PaginationRack::addFlags($this->paginationRack, PaginationRack::TOP, PaginationRack::BOTTOM);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,27 +3,40 @@
|
|||||||
namespace App\Tables;
|
namespace App\Tables;
|
||||||
|
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Mmt\GenericTable\Components\Column;
|
use Mmt\GenericTable\Components\Column;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
|
use Mmt\GenericTable\Enums\DatabaseEventQueryState;
|
||||||
|
use Mmt\GenericTable\Interfaces\IEvent;
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||||
|
use Mmt\GenericTable\Support\DatabaseEvent;
|
||||||
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
|
|
||||||
class TableWithRelationships implements IGenericTable
|
class TableWithRelationships implements IGenericTable, IEvent
|
||||||
{
|
{
|
||||||
public Model|string $model;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
public ColumnCollection $columns;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->model = new Product();
|
$columns = new ColumnCollection()->add(
|
||||||
|
|
||||||
$this->columns = new ColumnCollection()->add(
|
|
||||||
new Column('Name'),
|
new Column('Name'),
|
||||||
new Column('Department', 'subDepartment.department.name'),
|
new Column('Department'),
|
||||||
new Column('SubDepartment', 'subDepartment.name'),
|
new Column('SubDepartment'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->tableSettings = new GenericTableSettings(new Product(), $columns, true);
|
||||||
|
}
|
||||||
|
public function dispatchCallback(\Mmt\GenericTable\Support\EventArgs $arguments): void
|
||||||
|
{
|
||||||
|
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'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,16 @@ use App\Models\Product;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||||
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
|
|
||||||
class TableWithnNoSettings implements IGenericTable
|
class TableWithnNoSettings implements IGenericTable
|
||||||
{
|
{
|
||||||
public Model|string $model = Product::class;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
public ColumnCollection $columns;
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->tableSettings = new GenericTableSettings(
|
||||||
|
Product::class
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,48 +3,56 @@
|
|||||||
namespace App\Tables\Traits;
|
namespace App\Tables\Traits;
|
||||||
|
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Mmt\GenericTable\Attributes\CellFormatter;
|
use Mmt\GenericTable\Attributes\CellFormatter;
|
||||||
use Mmt\GenericTable\Attributes\MappedColumn;
|
|
||||||
use Mmt\GenericTable\Components\Column;
|
use Mmt\GenericTable\Components\Column;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
use Mmt\GenericTable\Enums\ColumnSettingFlags;
|
use Mmt\GenericTable\Enums\PaginationRack;
|
||||||
|
use Mmt\GenericTable\Interfaces\ICellData;
|
||||||
|
use Mmt\GenericTable\Interfaces\IRowData;
|
||||||
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
|
|
||||||
trait WithColumnFormatter
|
trait WithColumnFormatter
|
||||||
{
|
{
|
||||||
public Model|string $model = Product::class;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
public ColumnCollection $columns;
|
public int $paginationRack = 0;
|
||||||
|
|
||||||
|
public int $rowsPerPage = 10;
|
||||||
|
|
||||||
|
public array $rowsPerPageOptions = [10,20,40,60,80];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->columns = ColumnCollection::make(
|
$columns = ColumnCollection::make(
|
||||||
new Column('Id'),
|
new Column('Id'),
|
||||||
new Column('Name'),
|
new Column('Name'),
|
||||||
new Column('Description'),
|
new Column('Description'),
|
||||||
new Column('Price'),
|
new Column('Price'),
|
||||||
new Column('Stock'),
|
new Column('Stock'),
|
||||||
new Column('SubDepartment', 'subDepartment.name'),
|
new Column('SubDepartment', 'subDepartment.name'),
|
||||||
new Column('Empty Column')->withSettings(ColumnSettingFlags::EMPTY),
|
new Column('Empty Column')->empty(),
|
||||||
new Column('Empty Hook')->withSettings(ColumnSettingFlags::EMPTY)->hookFormatter(fn($rowModel) => $this->emptyCol($rowModel)),
|
new Column('Empty Hook')->empty()->hookFormatter(fn(IRowData $row) => $this->emptyCol($row)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->tableSettings = new GenericTableSettings(Product::class, $columns);
|
||||||
|
|
||||||
|
PaginationRack::addFlags($this->paginationRack, PaginationRack::TOP, PaginationRack::BOTTOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function emptyCol($model)
|
public function emptyCol(IRowData $row)
|
||||||
{
|
{
|
||||||
return '<i class = "text-danger">'.$model->id.'</i>';
|
return '<i class = "text-danger">'.$row->get('id').'</i>';
|
||||||
}
|
}
|
||||||
|
|
||||||
#[CellFormatter('price')]
|
#[CellFormatter('price')]
|
||||||
public function priceFormatter(Model $modelItem)
|
public function priceFormatter(ICellData $cell, IRowData $row)
|
||||||
{
|
{
|
||||||
return "<b class = 'text-primary'>\$</b> {$modelItem->price}";
|
return "<b class = 'text-primary'>\$</b> {$cell->value}";
|
||||||
}
|
}
|
||||||
|
|
||||||
#[CellFormatter('id')]
|
#[CellFormatter('id')]
|
||||||
public function idFormatter(Model $modelItem)
|
public function idFormatter(ICellData $cell, IRowData $row)
|
||||||
{
|
{
|
||||||
return '<b class = "text-primary">#</b> '.$modelItem->id;
|
return '<b class = "text-primary">#</b> '.$cell->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,24 +3,27 @@
|
|||||||
namespace App\Tables\Traits;
|
namespace App\Tables\Traits;
|
||||||
|
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Mmt\GenericTable\Components\Column;
|
use Mmt\GenericTable\Components\Column;
|
||||||
use Mmt\GenericTable\Components\ColumnCollection;
|
use Mmt\GenericTable\Components\ColumnCollection;
|
||||||
use Mmt\GenericTable\Enums\ColumnSettingFlags;
|
use Mmt\GenericTable\Enums\ColumnSettingFlags;
|
||||||
|
use Mmt\GenericTable\Support\GenericTableSettings;
|
||||||
|
|
||||||
trait WithExportableProductColumns
|
trait WithExportableProductColumns
|
||||||
{
|
{
|
||||||
public Model|string $model = Product::class;
|
public GenericTableSettings $tableSettings;
|
||||||
|
|
||||||
public ColumnCollection $columns;
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->columns = ColumnCollection::make(
|
$columns = ColumnCollection::make(
|
||||||
new Column('Name')->withSettings(ColumnSettingFlags::EXPORTABLE),
|
new Column('Name')->withSettings(ColumnSettingFlags::EXPORTABLE),
|
||||||
new Column('Description')->withSettings(ColumnSettingFlags::EXPORTABLE),
|
new Column('Description')->withSettings(ColumnSettingFlags::EXPORTABLE),
|
||||||
new Column('Price')->withSettings(ColumnSettingFlags::EXPORTABLE),
|
new Column('Price')->withSettings(ColumnSettingFlags::EXPORTABLE),
|
||||||
new Column('Stock')->withSettings(ColumnSettingFlags::EXPORTABLE)
|
new Column('Stock')->withSettings(ColumnSettingFlags::EXPORTABLE)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->tableSettings = new GenericTableSettings(
|
||||||
|
Product::class,
|
||||||
|
$columns
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,19 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-8">
|
<div class="col-7">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body p-0">
|
||||||
@generic_table($products)
|
@generic_table($products)
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="col-4">
|
<div class="col-5">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body p-0">
|
||||||
@generic_table($departments)
|
@generic_table($departments)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user