setActionButton

setActionButton(string $label, string $cssClassIcon,callable $urlCallback[, boolean $newTab])

setActionButton is used when we need to add extra action buttons to the rows of the datagrid. The functionality is simple and it takes the below arguments:

  1. label is the label that the button will have. For example "Photos"
  2. cssClassIcon is css that the icon at the left will have. You can use the default CSS from font-awesome but you can also use your own. For example "fa fa-image"
  3. urlCallback is the callback that it will be called in every row so you can get the custom URL that the button will have. Have in mind that this will redirect you to another page
  4. newTab is a boolean (true or false). The default value is false. This is used in case you need to open the link in new tab

You can see an example of the setActionButton below:

$crud->setActionButton('Avatar', 'fa fa-user', function ($row) {
    return '/view_avatar/' . $row->url;
}, true);

A full working example can be found below:

$crud->setTable('employees');
$crud->setSubject('Employee', 'Employees');
$crud->setRelation('officeCode','offices','city');
$crud->displayAs('officeCode','City');
$crud->unsetDelete();

$crud->setActionButton('Avatar', 'fa fa-user', function ($row) {
    return '#/avatar/' . $row->employeeNumber;
});

You can see the result of the above code below. In order to see the functionality of the action buttons, press the "Avatar" button in any of the rows, and you will see that there is a change in the top of the URL with #/avatar/[row-id] . We haven't provided a full URL just to not break the demo page or to redirect you to another page.