- Posts: 125
- Thank you received: 3
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var thisQuestion = $('#question{QID}'); // The row numbers that you want preceded by a blank row var rowNumbers = [1, 7, 10, 13]; // Create a clean clone of a row var rowClone = $('tr.subquestions-list:eq(0)', thisQuestion).clone(); $(rowClone).attr('id', '').removeClass('array1 array2 ').addClass('inserted-row'); $('td, th', rowClone).attr('class', '').html(''); // Insert the blank rows var rowNumbers = rowNumbers.reverse(); $(rowNumbers).each(function(i, val) { $('tr.subquestions-list:eq('+(val-1)+')', thisQuestion).before($(rowClone).clone()); }); // Fix up the row classes var rowClass = 1; $('tr.subquestions-list', thisQuestion).each(function(i) { if($(this).hasClass('inserted-row')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2 ') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); }); </script>
.inserted-row th, .inserted-row td { background: #999; padding: 8px !important; }
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var thisQuestion = $('#question{QID}'); // The row numbers that you want preceded by a blank row var rowNumbers = [1, 7, 10, 13]; // The row labels var rowLabels = ['Label 1', 'label 2', 'Label 3', 'Label 4']; // Create a clean clone of a row var rowClone = $('tr.subquestions-list:eq(0)', thisQuestion).clone(); $(rowClone).attr('id', '').removeClass('array1 array2 ').addClass('inserted-row'); $('td, th', rowClone).attr('class', '').html(''); // Insert the blank rows var rowNumbers = rowNumbers.reverse(); $(rowNumbers).each(function(i, val) { $('tr.subquestions-list:eq('+(val-1)+')', thisQuestion).before($(rowClone).clone()); }); // Insert the row labels $(rowLabels).each(function(i, val) { $('tr.inserted-row th:eq('+i+')', thisQuestion).text(val); }); // Fix up the row classes var rowClass = 1; $('tr.subquestions-list', thisQuestion).each(function(i) { if($(this).hasClass('inserted-row')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2 ') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); }); </script>
.inserted-row th, .inserted-row td { background: #999; padding: 8px !important; } .inserted-row th { color: #FFF; font-weight: bold; }