kdion4891 / laravel-livewire-tables

A dynamic, responsive Laravel Livewire table component with searching, sorting, checkboxes, and pagination.
302 stars 41 forks source link

bulk delete via checkbox deletes all - not just those in view #27

Open snapey opened 4 years ago

snapey commented 4 years ago

In other places where I check-all, I expect the operation to be limited to those in view.

The action of checking all causes every model to be deleted, not just those visible on page1

I extended the warning message to indicate this, but I think the default behaviour should be to only select the models on view.

I also overrode the updatedSearch() function so that it clears previous checkbox selection when making a new search so that items not in view are not accidentally deleted.

    public function updatedSearch()
    {
        $this->gotoPage(1);
        $this->checkbox_all = false;
        $this->checkbox_values=[];
    }
snapey commented 4 years ago

I created a workaround in the updatedCheckboxAll() by including the paginator. Might be useful to someone...

public function updatedCheckboxAll()
    {
        $this->checkbox_values = [];

        if ($this->checkbox_all) {
            $this->models()->paginate($this->per_page)->each(function ($model) {
                $this->checkbox_values[] = (string) $model->{$this->checkbox_attribute};
            });
        }
    }