Power-Components / livewire-powergrid

⚡ PowerGrid generates modern, powerful and easy-to-customize data tables using Laravel Livewire.
https://livewire-powergrid.com
MIT License
1.5k stars 219 forks source link

How to customize edit to pass parameter to your code and in delete button if you want to use sweet alert? #560

Closed anonymouse703 closed 2 years ago

anonymouse703 commented 2 years ago

Feature Request

Can customize button on edit and delete so that I can pass parameter in my code and can use sweet alert on delete

Summary

To be able to pass parameter in edit function and use alert warning before delete to avoid accidental mis-click

Why is this needed?

This is to prevent automatic delete of a record if a user accidentally click the delete button

Suggested Solution(s)

Add SWAL on delete

Other problem

I have this problem since the default in the button is route but in my web.php it's different since I only get the component class to display and let wire:click and render do the display and if I dophp artisan route:list the the name of the route is not display and also I usually used wire:click in most of the button in edit and delete

this is my route

use App\Http\Livewire\discount\DiscountList;
Route::get('/discount', DiscountList::class)->name('discount');

In the default button of power grid is something like this

Button::make('edit', 'Edit')
               ->class('bg-indigo-500 cursor-pointer text-white px-3 py-2.5 m-1 rounded text-sm')
               ->route('discount.edit', ['discount' => 'id']),

but in my recent project I used bootstrap dataTable and I did like this

<button wire:click="editClientContact({{ $data->id }})" class="btn btn-info delete-header m-1 btn-sm" title="Edit"><i class="fa fa-pencil" aria-hidden="true"></i></button>

The scenario is I used modal in my forms so if I click edit I want to pass the id in wire:click to trigger my code same as in delete button to avoid accidental click of the user

luanfreitasdev commented 2 years ago

Hello!. It is not good practice to add too many responsibilities to a component.

As a suggestion, I would do the following:

I'll convert it into discussions so we can follow along. Let me know if it worked!.

Thanks