Uploading content
This commit is contained in:
215
app/Livewire/Examples/BasicTableComponent.php
Normal file
215
app/Livewire/Examples/BasicTableComponent.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Examples;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\View\View;
|
||||
use Livewire\Attributes\On;
|
||||
use Mmt\GenericTable\Attributes\BulkAction;
|
||||
use Mmt\GenericTable\Attributes\BulkActionGroup;
|
||||
use Mmt\GenericTable\Attributes\CellFormatter;
|
||||
use Mmt\GenericTable\Attributes\Column;
|
||||
use Mmt\GenericTable\Attributes\ColumnFilter;
|
||||
use Mmt\GenericTable\Attributes\ColumnSettings;
|
||||
use Mmt\GenericTable\Attributes\MappedColumn;
|
||||
use Mmt\GenericTable\Attributes\MappedRoute;
|
||||
use Mmt\GenericTable\Attributes\OnReorder;
|
||||
use Mmt\GenericTable\BulkActionSettings;
|
||||
use Mmt\GenericTable\ColumnSettingFlags;
|
||||
use Mmt\GenericTable\CommonDateFilter;
|
||||
use Mmt\GenericTable\ExportSettings;
|
||||
use Mmt\GenericTable\FilterType;
|
||||
use Mmt\GenericTable\Interfaces\IActionColumn;
|
||||
use Mmt\GenericTable\Interfaces\IDragDropReordering;
|
||||
use Mmt\GenericTable\Interfaces\IExportable;
|
||||
use Mmt\GenericTable\Interfaces\IGenericTable;
|
||||
use Mmt\GenericTable\Interfaces\IPaginationRack;
|
||||
use Mmt\GenericTable\Interfaces\IRowsPerPage;
|
||||
use Mmt\GenericTable\PaginationRack;
|
||||
|
||||
|
||||
class BasicTableComponent implements IGenericTable
|
||||
{
|
||||
#[MappedColumn]
|
||||
#[ColumnSettings(ColumnSettingFlags::NONE, ColumnSettingFlags::SORTEABLE)]
|
||||
public int $Id;
|
||||
|
||||
|
||||
#[Column('Name')]
|
||||
#[ColumnSettings(ColumnSettingFlags::SORTEABLE, ColumnSettingFlags::EXPORTABLE, ColumnSettingFlags::SEARCHABLE)]
|
||||
#[MappedRoute('product_details', ['id' => ':id'])]
|
||||
public string $Name;
|
||||
|
||||
|
||||
#[MappedColumn]
|
||||
#[ColumnSettings(ColumnSettingFlags::SORTEABLE, ColumnSettingFlags::SEARCHABLE)]
|
||||
public string $Description;
|
||||
|
||||
|
||||
#[MappedColumn]
|
||||
#[ColumnSettings(ColumnSettingFlags::SORTEABLE, ColumnSettingFlags::SEARCHABLE, ColumnSettingFlags::EXPORTABLE)]
|
||||
public float $Price;
|
||||
|
||||
|
||||
#[MappedColumn]
|
||||
#[ColumnSettings(ColumnSettingFlags::SORTEABLE)]
|
||||
public string $Status;
|
||||
|
||||
#[MappedColumn('subDepartment.name')]
|
||||
public string $SubDepartment;
|
||||
|
||||
#[MappedColumn('subDepartment.department.name')]
|
||||
#[ColumnSettings(ColumnSettingFlags::EXPORTABLE)]
|
||||
public string $Department;
|
||||
|
||||
#[MappedColumn]
|
||||
#[ColumnSettings(ColumnSettingFlags::DEFAULT_SORT_ASC)]
|
||||
public string $Order;
|
||||
|
||||
|
||||
// #[MappedColumn]
|
||||
// #[ColumnSettings(ColumnSettingFlags::HIDDEN)]
|
||||
// public string $DepartmentId;
|
||||
|
||||
public Model|string $model;
|
||||
|
||||
public int $rowsPerPage = 10;
|
||||
public array $rowsPerPageOptions = [10,20,40,60,100];
|
||||
public int $actionColumnIndex = -1;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = Product::class;
|
||||
}
|
||||
|
||||
|
||||
#[CellFormatter('price')]
|
||||
public function priceFormatter(Model $row)
|
||||
{
|
||||
return "$$row->price";
|
||||
}
|
||||
|
||||
// #[CellFormatter('department.name')]
|
||||
// public function categoryFormatter(Model $row)
|
||||
// {
|
||||
// return '--eep--';
|
||||
// }
|
||||
|
||||
|
||||
#[ColumnFilter('status', FilterType::SINGLE_SELECTION)]
|
||||
public function statusFilter()
|
||||
{
|
||||
return [
|
||||
'out_of_stock',
|
||||
'discontinued',
|
||||
'available',
|
||||
'All' => -1
|
||||
];
|
||||
}
|
||||
|
||||
// #[ColumnFilter('name', FilterType::MULTI_SELECTION)]
|
||||
// public function brandsFilter()
|
||||
// {
|
||||
// return [
|
||||
// 'product 1',
|
||||
// 'product 2',
|
||||
// 'Addidas',
|
||||
// 'All'
|
||||
// ];
|
||||
// }
|
||||
|
||||
// #[ColumnFilter('price', FilterType::MULTI_SELECTION)]
|
||||
// public function namesFilter()
|
||||
// {
|
||||
// return [
|
||||
// 'Pedro',
|
||||
// 'Pablo',
|
||||
// 'Juan',
|
||||
// 'All'
|
||||
// ];
|
||||
// }
|
||||
|
||||
// #[ColumnFilter('created_at', FilterType::DATE_RANGE)]
|
||||
// public function dateRangeFilter()
|
||||
// {
|
||||
// $flags = 0;
|
||||
|
||||
// CommonDateFilter::addFlag($flags,
|
||||
// CommonDateFilter::ALL_RANGES,
|
||||
// );
|
||||
|
||||
// return $flags;
|
||||
// }
|
||||
|
||||
// public function onBeforeExport(): ExportSettings
|
||||
// {
|
||||
// return new ExportSettings();
|
||||
// }
|
||||
|
||||
public function onExport(array &$headers, array &$rows): void
|
||||
{
|
||||
dd($headers, $rows);
|
||||
}
|
||||
|
||||
|
||||
public function actionView() : View
|
||||
{
|
||||
return view('action-column');
|
||||
}
|
||||
|
||||
|
||||
public function edit()
|
||||
{
|
||||
throw new \Exception('Not implemented');
|
||||
}
|
||||
|
||||
|
||||
#[OnReorder]
|
||||
public function onReorderCallback(int $newPosition, $oldPosition, Model $model)
|
||||
{
|
||||
/**
|
||||
* If method exists, should return TRUE indicating to the subsystem that
|
||||
* this method will handle the reording.
|
||||
* If you do not explicitly return boolean, the subsystem will use FALSE as a default returned value
|
||||
*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#[BulkAction]
|
||||
public function deleteAllUsers($data)
|
||||
{
|
||||
dd($data);
|
||||
}
|
||||
|
||||
#[BulkActionGroup('Marketing', 'Promotions')]
|
||||
#[BulkAction]
|
||||
public function sendHedgeFundPromotions($data)
|
||||
{
|
||||
dd($data);
|
||||
}
|
||||
|
||||
#[BulkActionGroup('Marketing', 'Promotions')]
|
||||
#[BulkAction]
|
||||
public function sendFundingPromotions($data)
|
||||
{
|
||||
dd($data);
|
||||
}
|
||||
|
||||
#[BulkActionGroup('Marketing', 'Promotions')]
|
||||
#[BulkAction(requestConfirmation: false)]
|
||||
public function uniqueTest($data)
|
||||
{
|
||||
dd($data);
|
||||
}
|
||||
|
||||
// #[BulkActionGroup('Accounts')]
|
||||
// #[BulkAction]
|
||||
// public function sendVerificationEmails(BulkActionSettings $data)
|
||||
// {
|
||||
|
||||
// dd($data->getSelection());
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user