Thanks a lot for your answer and sorry for reaching you that late.
Your hint was very useful but in the end, a friend of mine and we came up with a different solution. We basically going to check if the visible rows of the answer list contain an ID with a certain STRING.
We hope that this going to help someone in the future.
Your hint was very useful but in the end, a friend of mine and we came up with a different solution. We basically going to check if the visible rows of the answer list contain an ID with a certain STRING.
We hope that this going to help someone in the future.
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
var columnsLength = $('tr.answers-list:eq(0) > *', thisQuestion).length;
var found = {
'de0': false,
'be0': false,
'bg0': false,
'dk0': false,
'ee0': false,
};
var position = {
'de0': '0',
'be0': '7',
'bg0': '11',
'dk0': '16',
'ee0': '21',
}
var name = {
'de0': 'Germany',
'be0': 'Belgium',
'bg0': 'Bulgaria',
'dk0': 'Denmark',
'ee0': 'Estonia',
}
var find = [ 'de0', 'be0', 'bg0', 'dk0', 'ee0' ];
$('tr.answers-list:visible').each(function(){
var identifier = $(this).attr('id');
$.each(find, function(index, value){
if(identifier.indexOf(value) !== -1) {
found[value] = true;
}
});
});
var found_keys = Object.keys(found);
console.log(found_keys);
$.each(found_keys, function(index, value){
if(found[value]) {
$('tr.answers-list:eq(' + position[value] + ')').before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+name[value]+'</th></tr>');
}
});
var rowClass = 1;
$('table.subquestions-list tbody tr', thisQuestion).each(function(i) {
if($(this).hasClass('sub-header-row')) {
rowClass = 1
}
else {
rowClass++;
$(this).removeClass('array1 array2')
if(rowClass % 2 == 0) {
$(this).addClass('array2');
}
else {
$(this).addClass('array1');
}
}
});
});
</script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
var columnsLength = $('tr.answers-list:eq(0) > *', thisQuestion).length;
var found = {
'de0': false,
'be0': false,
'bg0': false,
'dk0': false,
'ee0': false,
};
var position = {
'de0': '0',
'be0': '7',
'bg0': '11',
'dk0': '16',
'ee0': '21',
}
var name = {
'de0': 'Germany',
'be0': 'Belgium',
'bg0': 'Bulgaria',
'dk0': 'Denmark',
'ee0': 'Estonia',
}
var find = [ 'de0', 'be0', 'bg0', 'dk0', 'ee0' ];
$('tr.answers-list:visible').each(function(){
var identifier = $(this).attr('id');
$.each(find, function(index, value){
if(identifier.indexOf(value) !== -1) {
found[value] = true;
}
});
});
var found_keys = Object.keys(found);
console.log(found_keys);
$.each(found_keys, function(index, value){
if(found[value]) {
$('tr.answers-list:eq(' + position[value] + ')').before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+name[value]+'</th></tr>');
}
});
var rowClass = 1;
$('table.subquestions-list tbody tr', thisQuestion).each(function(i) {
if($(this).hasClass('sub-header-row')) {
rowClass = 1
}
else {
rowClass++;
$(this).removeClass('array1 array2')
if(rowClass % 2 == 0) {
$(this).addClass('array2');
}
else {
$(this).addClass('array1');
}
}
});
});
</script>