Examples updated

This commit is contained in:
David
2025-04-02 04:54:28 -04:00
parent 63779f8bad
commit 585c32d0cd
4 changed files with 24 additions and 6 deletions

View File

@@ -6,12 +6,15 @@ use App\Tables\Traits\WithColumnFormatter;
use Mmt\GenericTable\Attributes\MappedRoute;
use Mmt\GenericTable\Components\Column;
use Mmt\GenericTable\Components\ColumnCollection;
use Mmt\GenericTable\Interfaces\IDragDropReordering;
use Mmt\GenericTable\Interfaces\IGenericTable;
class TableWithBindedRoutes implements IGenericTable
class TableWithBindedRoutes implements IGenericTable, IDragDropReordering
{
use WithColumnFormatter;
public string $orderingColumn;
public function __construct()
{
$this->columns = ColumnCollection::make(

View File

@@ -6,6 +6,7 @@ use App\Models\Product;
use App\Tables\Traits\WithExportableProductColumns;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Response;
use Mmt\GenericTable\Attributes\CellFormatter;
use Mmt\GenericTable\Components\ColumnCollection;
use Mmt\GenericTable\Interfaces\IExportable;
use Mmt\GenericTable\Interfaces\IGenericTable;
@@ -19,7 +20,15 @@ class TableWithExport implements IGenericTable, IExportable
public function onExport(ExportEventArgs $args) : BinaryFileResponse|Response
{
$args->query->take(5);
$args->settings->useFormatters = true;
$args->settings->fileName = 'products';
return $args->export();
}
#[CellFormatter('price')]
public function priceFormatter($rowModel)
{
return '$'.$rowModel->price;
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Tables;
use App\Models\Product;
use Illuminate\Database\Eloquent\Model;
use Mmt\GenericTable\Components\Column;
use Mmt\GenericTable\Components\ColumnCollection;
use Mmt\GenericTable\Enums\CommonDateFilter;
use Mmt\GenericTable\Interfaces\IDateRangeFilter;
@@ -31,8 +32,6 @@ class TableWithFilters implements IGenericTable, IEvent, IDateRangeFilter, ISing
public SelectionFilterSettings $multiSelectionFilterSettings;
public bool $isTableLoaderEnabled = true;
public string $orderingColumn = 'order';
@@ -42,6 +41,13 @@ class TableWithFilters implements IGenericTable, IEvent, IDateRangeFilter, ISing
CommonDateFilter::LAST_2_MONTHS,
CommonDateFilter::LAST_3_MONTHS
);
$this->columns = ColumnCollection::make(
new Column('Id')->hookFormatter(fn($row) => '#'.$row->id),
new Column('Order')->sortable()->defaultSort(),
new Column('Name'),
new Column('Price')
);
$this->singleSelectionFilterSettings = new SelectionFilterSettings('status')
->add('Out of stock', 'out_of_stock')
@@ -68,8 +74,8 @@ class TableWithFilters implements IGenericTable, IEvent, IDateRangeFilter, ISing
public function tableLoadingIndicatorView(): \Illuminate\View\View
public function tableLoadingIndicatorView(string $id): \Illuminate\View\View
{
return view('custom-loader');
return view('custom-loader', ['genericId' => $id]);
}
}