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:

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

Note: For the community edition the $row object is at the second argument of the callback function (instead of first which is on Enterprise one). For example:

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

A full working example can be found below:

$crud->setSubject('Employee', 'Employees');

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

You can see the result of the above code here. In order to see the functionality of the action buttons, press the More button in any of the rows.