Refactor table components to use GenericTableSettings and remove deprecated classes

This commit is contained in:
David
2025-04-25 01:19:30 -04:00
parent 7466083798
commit 9f12bc28d0
17 changed files with 177 additions and 203 deletions

View File

@@ -4,35 +4,35 @@ 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;
use Mmt\GenericTable\Interfaces\IRowData;
use Mmt\GenericTable\Support\GenericTableSettings;
class TableWithCustomColumn implements IGenericTable
{
public Model|string $model;
public ColumnCollection $columns;
public GenericTableSettings $tableSettings;
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) {
$columns = new ColumnCollection();
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';
}
else {
return $icons['bag-x'] . ' text-danger';
}
}));
$this->tableSettings = new GenericTableSettings(new Product(), $columns);
}
}