#FEAT
+ Added new example about the new feature: custom column
This commit is contained in:
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
Reference in New Issue
Block a user