I have a table and each row should link to a page.
I want to keep the structure of the html as is (not a bunch of divs and a grid like Wrapping HTML table rows in <a> tags)
Everything works with the javascript, but I am missing the bottom left tooltip that shows the url on hover from an tag. I also want the option to open in a new tab with CMD (mac) or CTRL (windows/linux).
I am currently doing the solution with jQuery:
$('.clickable-row').on('click', function () {
const url = $(this).attr('data-url')
if (typeof url === 'string') {
window.location.href = url
}
});
My html (twig):
<table class='table'>
<thead>
<tr>
{% for h in data.header %}
<th>{{h|trans}}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in data.rows %}
{% set url = data.getOnClickURL(loop.index - 1) %}
<tr {% if url %} class='clickable-row' data-url="{{url}}" {% endif %}>
{% for r in row %}
<td>{{r|trans}}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>