refactor(datatable): menjadikan dinamis kolom pengatur sorting
This commit is contained in:
parent
58e2c04116
commit
fac455e7f1
@ -3,6 +3,7 @@
|
|||||||
namespace App\Livewire\Datatable\Studio\Manage;
|
namespace App\Livewire\Datatable\Studio\Manage;
|
||||||
|
|
||||||
use App\Models\Purchase;
|
use App\Models\Purchase;
|
||||||
|
use App\Traits\Datatable\WithAppendColumn;
|
||||||
use App\Traits\Datatable\WithConfiguration;
|
use App\Traits\Datatable\WithConfiguration;
|
||||||
use App\Traits\Datatable\WithPrependColumn;
|
use App\Traits\Datatable\WithPrependColumn;
|
||||||
use App\Traits\WithMediaHandler;
|
use App\Traits\WithMediaHandler;
|
||||||
@ -13,10 +14,14 @@
|
|||||||
|
|
||||||
class PurchasesTable extends DataTableComponent
|
class PurchasesTable extends DataTableComponent
|
||||||
{
|
{
|
||||||
use WithConfiguration, WithMediaHandler, WithPrependColumn;
|
use WithAppendColumn, WithConfiguration, WithMediaHandler, WithPrependColumn;
|
||||||
|
|
||||||
protected $model = Purchase::class;
|
protected $model = Purchase::class;
|
||||||
|
|
||||||
|
protected string $sortColumn = 'purchase_date';
|
||||||
|
|
||||||
|
protected string $sortDirection = 'desc';
|
||||||
|
|
||||||
public function columns(): array
|
public function columns(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -33,11 +33,15 @@ public function configure(): void
|
|||||||
|
|
||||||
// Sorting
|
// Sorting
|
||||||
->setSortingPillsDisabled()
|
->setSortingPillsDisabled()
|
||||||
->setSingleSortingEnabled()
|
->setSingleSortingEnabled();
|
||||||
->setDefaultSort('created_at', 'desc')
|
|
||||||
|
|
||||||
// Filter
|
$defaultColumn = property_exists($this, 'sortColumn') ? $this->sortColumn : 'created_at';
|
||||||
->setFilterPillsDisabled()
|
$defaultDirection = property_exists($this, 'sortDirection') ? $this->sortDirection : 'desc';
|
||||||
|
|
||||||
|
$this->setDefaultSort($defaultColumn, $defaultDirection);
|
||||||
|
|
||||||
|
// Filter
|
||||||
|
$this->setFilterPillsDisabled()
|
||||||
->setFilterPopoverAttributes(
|
->setFilterPopoverAttributes(
|
||||||
[
|
[
|
||||||
'class' => 'w-50',
|
'class' => 'w-50',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user