laravel-livewire-tables icon indicating copy to clipboard operation
laravel-livewire-tables copied to clipboard

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

Open snapey opened this issue 5 years ago • 1 comments

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 avatar May 12 '20 18:05 snapey

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};
            });
        }
    }

snapey avatar May 12 '20 18:05 snapey