crudbooster icon indicating copy to clipboard operation
crudbooster copied to clipboard

Action buttons per row

Open kazak71 opened this issue 7 years ago • 6 comments

How can I enable/disable action buttons per row in index (detail,edit,delete)? I know I can create custom action buttons and show them conditionally, but in this case I have to hide default buttons. I set my custom button for edit action and it works fine. But when I make settings like this: ... $this->global_privilege = true; $this->button_edit = false; .... and click on Edit (my custom button), I see message that I have not privilege to edit this resource.

Please help me! Thanks in advance!

kazak71 avatar May 21 '17 23:05 kazak71

try $this->button_table_action = false

fherryfherry avatar May 23 '17 01:05 fherryfherry

image Can the button hide if certain conditions, like the picture above. If status Open button edit and delete is hide ?

moxie88 avatar Oct 23 '17 08:10 moxie88

I tried to do it this way:

  1. Disabling button edit:
$this->button_edit = false;
  1. Adding an action:
$this->addaction[] = [
        'title' => 'Editar', 'url' => CRUDBooster::mainpath('edit/[id]'),
        'icon' => 'fa fa-pencil', 'color' => 'success', 'showIf' => '[automatico] == 1'
];

But then editing is disabled for everyone. So, that's not the way.

I "solved" it, by doing this:

  1. Enable again button edit:
$this->button_edit = true;
  1. Overriding getEdit():
public function getEdit($id)
    {
        $comparendo = Comparendo::find($id);
        if ($comparendo->automatico == true) {
            CRUDBooster::redirectBack(
                'Los comparendos <b>electrónicos automáticos</b>, es decir, '
                    . 'que son generados por este sistema, <b>no se pueden editar</b>.'
            );
        }
        return parent::getEdit($id);
    }

andreshg112 avatar Jul 18 '18 20:07 andreshg112

You could also try this way with url variables:

$this->button_edit= isset($_GET['variable']) ? false : true;

renzocastillo avatar Apr 17 '19 19:04 renzocastillo

I tried to do it this way:

  1. Disabling button edit:
$this->button_edit = false;
  1. Adding an action:
$this->addaction[] = [
        'title' => 'Editar', 'url' => CRUDBooster::mainpath('edit/[id]'),
        'icon' => 'fa fa-pencil', 'color' => 'success', 'showIf' => '[automatico] == 1'
];

But then editing is disabled for everyone. So, that's not the way.

I "solved" it, by doing this:

  1. Enable again button edit:
$this->button_edit = true;
  1. Overriding getEdit():
public function getEdit($id)
    {
        $comparendo = Comparendo::find($id);
        if ($comparendo->automatico == true) {
            CRUDBooster::redirectBack(
                'Los comparendos <b>electrónicos automáticos</b>, es decir, '
                    . 'que son generados por este sistema, <b>no se pueden editar</b>.'
            );
        }
        return parent::getEdit($id);
    }

Thank you! this worked great!

renzocastillo avatar May 17 '21 23:05 renzocastillo

I did it in a different way, it just worked for me using query.

image

bhayron avatar Jun 21 '21 18:06 bhayron