actions = new Collection(); $this->appendDefaultAction(); } /** * Append default action(batch delete action). * * return void */ protected function appendDefaultAction() { $this->add(new BatchDelete(trans('admin.delete'))); } /** * Disable delete. * * @return $this */ public function disableDelete(bool $disable = true) { $this->enableDelete = ! $disable; return $this; } /** * Disable delete And Hode SelectAll Checkbox. * * @return $this */ public function disableDeleteAndHodeSelectAll() { $this->enableDelete = false; $this->isHoldSelectAllCheckbox = true; return $this; } /** * Add a batch action. * * @param BatchAction $action * * @return $this */ public function add(BatchAction $action) { $action->selectorPrefix = '.grid-batch-action-'.$this->actions->count(); $this->actions->push($action); return $this; } /** * Prepare batch actions. * * @return void */ protected function prepareActions() { foreach ($this->actions as $action) { $action->setGrid($this->parent); } } /** * Scripts of BatchActions button groups. */ protected function setupScript() { $name = $this->parent->getName(); $allName = $this->parent->selectAllName(); $rowName = $this->parent->rowName(); $selected = trans('admin.grid_items_selected'); $script = <<enableDelete) { $this->actions->shift(); } if ($this->actions->isEmpty()) { return ''; } $this->setupScript(); $this->prepareActions(); $data = [ 'actions' => $this->actions, 'selectAllName' => $this->parent->selectAllName(), 'isHoldSelectAllCheckbox' => $this->isHoldSelectAllCheckbox, ]; return view('admin::grid.batch-actions', $data)->render(); } }