Add or Update Button while using Action Rule #617
Answered
by
dansysanalyst
abhaypithadiya
asked this question in
Q&A
-
Hey! I have a delete button in my table I want to change that button to restore button when I use the soft deletes filter. How can I do that? |
Beta Was this translation helpful? Give feedback.
Answered by
dansysanalyst
Sep 8, 2022
Replies: 1 comment 5 replies
-
You can have a Delete and a Restore button and hide them accordingly to your Model state. use PowerComponents\LivewirePowerGrid\Rules\Rule;
use PowerComponents\LivewirePowerGrid\Header;
final class DishTable extends PowerGridComponent
{
//...
public function actionRules(): array
{
return [
//Hides delete button when row is trashed
Rule::button('delete')
->when(fn ($dish) => $dish->trashed() == true)
->hide(),
//Hides restore button when row is not trashed
Rule::button('restore')
->when(fn ($dish) => $dish->trashed() == false)
->hide(),
//Change row color for trashed rows
Rule::rows()
->when(fn ($dish) => $dish->trashed() == true)
->setAttribute('class', 'bg-red-100 hover:bg-red-200'),
];
}
public function setUp(): array
{
$this->showCheckBox();
return [
Header::make()
->showSoftDeletes()
->showSearchInput(),
//...
];
}
public function datasource(): ?Builder
{
return Dish::withTrashed()->with(['category:id,name', 'kitchen']);
}
//...
} Resulting in: |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
abhaypithadiya
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can have a Delete and a Restore button and hide them accordingly to your Model state.