<!DOCTYPE html><html lang="fr"><head> <meta charset="UTF-16"> <title>Fiche Séance</title> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" /> <style> * { font-family: 'Roboto'; } table { border-collapse: collapse; } th, td { border: 1px solid black; {% if page %} padding: 15px; {% endif %} } th { background-color: #cccccc; } tr:first-child td:nth-child(1), .mytable tr:first-child td:nth-child(2) { border:1px transparent; } </style></head><body ><div style="width: 100%; text-align: center"> <h1>Progression</h1></div><div id="bloc"><table id="myTable" style="width: 100%"> <tr> <th>Jour</th> <th>Séquence</th> <th>Séance</th> <th>Durée</th> </tr> {% set val = 0 %} {% set sequence = 0 %} {% set periodeCle = 0 %} {% set date = "" %} {% for progression_detail in progression.refProgressionDetails %} {% if progression_detail.refPeriodeCle is null%} {% if progression_detail.refSeance is not null%} {% if sequence != progression_detail.refSeance.refSequence.id %} {% set val = val+1 %} {% set sequence = progression_detail.refSeance.refSequence.id %} {% endif %} <tr> <td>{{ progression_detail.date ? progression_detail.date|date('d/m/Y') : '' }}</td> <td data-toregroup="{{ val }}-{{ progression_detail.refSeance ? progression_detail.refSeance.refSequence : '' }}">{{ progression_detail.refSeance ? progression_detail.refSeance.refSequence : '' }}</td> <td>{{ progression_detail.refSeance ? progression_detail.refSeance : '' }}</td> <td>{{ progression_detail.refSeance ? progression_detail.refSeance.duree : '' }}</td> </tr> {% else %} {% set val = val+1 %} <tr> <td>{{ progression_detail.date ? progression_detail.date|date('d/m/Y') : '' }}</td> <td data-toregroup="{{ val }}-{{ progression_detail.refSeance ? progression_detail.refSeance.refSequence : '' }}">{{ progression_detail.refSeance ? progression_detail.refSeance.refSequence : '<i>Non défini</i>' }}</td> <td>{{ progression_detail.refSeance ? progression_detail.refSeance : '<i>Non défini</i>' }}</td> <td>{{ progression_detail.refSeance ? progression_detail.refSeance.duree : '' }}</td> </tr> {% endif %} {% else %} {% if date != progression_detail.date|date('d/m/Y') %} {% set date = progression_detail.date|date('d/m/Y') %} {% if periodeCle != progression_detail.refPeriodeCle.id %} {% set val = val+1 %} {% set periodeCle = progression_detail.refPeriodeCle.id %} {% endif %} <tr style="background-color: {{ progression_detail.refPeriodeCle.refPeriodeType.couleur ~ '66' }}; color: {{ progression_detail.refPeriodeCle.refPeriodeType.couleur }}"> <td>{{ progression_detail.date ? progression_detail.date|date('d/m/Y') : '' }}</td> <td colspan="3" data-toregroup="{{ val }}" >{{ progression_detail.refPeriodeCle }}</td> </tr> {% endif %} {% endif %} {% endfor %}</table></div><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script><script> $(function(){ //assumption: the column that you wish to rowspan is sorted. //this is where you put in your settings var indexOfColumnToRowSpan = 1; var $table = $('#myTable'); //this is the code to do spanning, should work for any table var rowSpanMap = {}; $table.find('tr').each(function(){ var valueOfTheSpannableCell = $($(this).children('td')[indexOfColumnToRowSpan]).data("toregroup"); $($(this).children('td')[indexOfColumnToRowSpan]).attr('data-original-value', valueOfTheSpannableCell); rowSpanMap[valueOfTheSpannableCell] = true; }); console.log(rowSpanMap) for(var rowGroup in rowSpanMap){ console.log(rowGroup) var $cellsToSpan = $('td[data-original-value="'+rowGroup+'"]'); console.log($cellsToSpan); var numberOfRowsToSpan = $cellsToSpan.length; $cellsToSpan.each(function(index){ if(index==0){ $(this).attr('rowspan', numberOfRowsToSpan); }else{ $(this).hide(); } }); } })();</script></body></html>