Customize table fields with links (show actions)
I need to customize the table rendering in order to add the proper actions to show the associate record. I think the best way is to use the custom renderer approach, but I need some help to effectively implement it.
Warning: following code breaks searching functionality Currently working on fixing it (and see if it's worthwhile), let me know if a PR is wanted for this functionality
Update @ 18-01-2017: I have a complete fix for searching and a working version, if anyone is interested i could send the code or create a PR
Not sure if you still need anything for this but you can do this:
_datatable->setFields function in controller (replace the 'q' by whatever you bound your entity to):
$key => 'q.entity',
_datatable->setRenderer function in controller:
->setRenderer(
function(&$data) use ($controller_instance)
{
foreach($data as $key => $value)
{
if ($key === 0)
{
$data[$key] = $controller_instance
->get('templating')
->render(
'Main/Datatable/Renderers/entity.html.twig',
array(
'entity' => $value,
'path_name' => 'entity_show_route'
)
);
}
}
}
)
custom renderer twig:
{# app/Resources/views/Main/Datatable/Renderers/entity.html.twig #}
{% spaceless %}
{% if entity is not defined %}
missing parameters for rendering entity ({% if entity is not defined %}entity{% endif %})
{% else %}
{% if entity is defined and entity is not null and path_name is not defined %}
{{ entity }} {# calls the __toString() function of entity #}
{% elseif entity is defined and entity is not null %}
<a href="{{ path(path_name, {'id': entity.id}) }}">{{ entity }}</a> {# calls the __toString() function of entity #}
{% endif %}
{% endif %}
{% endspaceless %}