Examples updated
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="position-absolute top-0 start-0 w-100 h-100" style="display:none; background: rgba(0, 0, 0, 0.5); z-index: 100;" id = "generic_table_loader">
|
||||
<div class="position-absolute top-0 start-0 w-100 h-100" style="display:none; background: rgba(0, 0, 0, 0.5); z-index: 100;" id = "{{ $genericId }}_loading_indicator">
|
||||
<div class="d-flex h-100">
|
||||
<div class="m-auto d-flex flex-column">
|
||||
<div class="spinner-border mx-auto text-primary" role="status"></div>
|
||||
|
||||
Reference in New Issue
Block a user