public function dataTableActions(DataTable $dt, array $actions) { $code = '{ targets: ' . $dt->columnCount() . ', render: function(data, type, row) { ' . "\n" . 'return '; $first = true; foreach ($actions as $action) { if (!isset($action['link']) || !isset($action['name']) || !isset($action['label'])) { throw new LogicException('The action is missing one of the properties: link, name, label'); } if (!$first) { $code .= ' + '; } $first = false; if (isset($action['when'])) { $code .= '(row[\'' . $action['when'] . '\'] ? \'<a href="\' + row[\'' . $action['link'] . '\'] + \'" class="btn btn-xs ' . $action['label'] . '" role="button">' . $action['name'] . '</a> \' : \'\') '; } else { $code .= '\'<a href="\' + row[\'' . $action['link'] . '\'] + \'" class="btn btn-xs ' . $action['label'] . '" role="button">' . $action['name'] . '</a> \' '; } } $code .= ";\n } }"; return $code; }