MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 258 forks source link

edit and delete actions button each row #377

Open red8001 opened 2 years ago

red8001 commented 2 years ago

hi please can you help me how to add an editable row in datatable, i tried for myself to add a simple colum with action button but nothing working thanks for the help.

rikthomas commented 2 years ago

If you have declared a builder() method but no $public property, the model is returned as null and the delete method fails.

The workaround is to declare both a public property and builder method:

public $model = User::class

public function builder()
    {
        return User::where('hospital_id', Auth::user()->id);
    }

I have submitted a PR (#379) with a fix

red8001 commented 2 years ago

thanks yout for responding but i did not understand the goal here its to add an edit and delete button for each row
image so any idea ????

rikthomas commented 2 years ago

If you use the editable() method, it replaces that cell with a view that contains and Alpine/Livewire component where you can edit the data inline by clicking on the cell.

What do you want the edit button to do? If you want it to open a modal where the whole row is editable or make all the cells in the row editable, I think you will need to make your own custom view or callback.

red8001 commented 2 years ago

thanks for responding according to my project i need edit button to open a modal with all information about this row, editable method dont work for me as i want i fixed part of the problem in the controller i add a column to return a button like : Column::callback(['id'], function ($id) {
return "<button wire.click='showeditModal($id)' class='bg-white rounded-md p-2 inline-flex items-center justify-center text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500'>Edit";
})->label('Actions'), but the button dont show the model in my livewire componnent that second part of the problem how your apporach?? thanks

rikthomas commented 2 years ago

I've done this on a project. The approach I took was to make a custom view and then insert a Livewire component within that view with my modal and editable fields. I ended up with a simple custom view containing my component like this:

<div class="flex-1 flex justify-center">
    <livewire:update-ticket :ticket_id="$row->id" :key="$row->id">
</div>