app/Http/Livewire/Datatable.php: adding setTrashedColumns() and call it from mount()
This commit is contained in:
parent
6d988f925a
commit
c0e0357a43
1 changed files with 21 additions and 0 deletions
|
|
@ -81,6 +81,8 @@ class Datatable extends Component
|
|||
$this->route_edit = $route_edit;
|
||||
$this->route_delete = $route_delete;
|
||||
$this->route_restore = $route_restore;
|
||||
|
||||
$this->setTrashedColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -108,6 +110,25 @@ class Datatable extends Component
|
|||
return view('livewire.datatable', ['items' => $items]);
|
||||
}
|
||||
|
||||
private function setTrashedColumns()
|
||||
{
|
||||
if ($this->trashed) {
|
||||
// Add deleted_at columns.
|
||||
$this->columns['deleted_at'] = 'Deleted at';
|
||||
$this->sort_columns['deleted_at'] = 'deleted_at';
|
||||
} else {
|
||||
// Unset deleted_at columns.
|
||||
unset($this->columns['deleted_at']);
|
||||
unset($this->sort_columns['deleted_at']);
|
||||
|
||||
// if delete_at was the sorting column
|
||||
// revert back to default sorting.
|
||||
if ($this->sort == 'deleted_at') {
|
||||
$this->sort = $this->default_sort;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getRouteKeyProperty()
|
||||
{
|
||||
return Str::slug(get_class($this->model));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue