Hide empty rows of a Matrix

More
5 years 2 weeks ago #87952 by snieuw
snieuw created the topic: Hide empty rows of a Matrix
Hi everybody,
first of all: I know this was asked before. I just can not make this code work (taken from www.limesurvey.org/de/forum/can-i-do-thi...pty-rows-of-a-matrix ). Did something change there in the last updates? Unfortunately I'm not really fit in JavaScript, so please excuse if this is a stupid question. I have my questiongroup attached.

code in the description of the questiongroup:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		// Hide all rows without a row label
		$('table.question tbody').each(function(i, el){
 
			var rowLabel = $('th:first', el).text().replace(/[\s\n\t]/g,'');
 
			if(rowLabel == '' || rowLabel == 'Newansweroption') {
				$(el).hide();
			}
		});
 
		// Fix up row background colours
		$('table.question tbody:visible tr').each(function(i, el){
			$(el).removeClass('array1, array2');
			if(i % 2 == 0) {
				$(el).addClass('array2');
			}
			else {
				$(el).addClass('array1');
			}
		});
 
	});
</script>
 

Second question is te corresponding matrix, rows are filled correctly by the {if} statement, but empty rows are shown nevertheless.

Thanks a lot for any input!
Steffen
Attachments:

Please Log in to join the conversation.

More
5 years 2 weeks ago #88064 by tpartner
tpartner replied the topic: Hide empty rows of a Matrix
That group by itself doesn't help us see the problem.

Can you attach a sample survey?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 2 weeks ago #88067 by snieuw
snieuw replied the topic: Hide empty rows of a Matrix
Sorry, you are right of course. An example survey is attached. Code is in the group description, the only question that is in the group should not show the second (empty) row.

Thanks for helping :)
Steffen
Attachments:

Please Log in to join the conversation.

More
5 years 1 week ago #88087 by tpartner
tpartner replied the topic: Hide empty rows of a Matrix
The script above is for an array-numbers-checkbox question type.

For the plain array question type use this:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		// Hide all rows without a row label
		$('table.question tr[id^="javatbd"]').each(function(i, el){
 
			var rowLabel = $('th:first', el).text().replace(/[\s\n\t]/g,'');
 
			if(rowLabel == '') {
				$(el).hide();
			}
		});
 
		// Fix up row background colours
		$('table.question tr[id^="javatbd"]:visible').each(function(i, el){
			$(el).removeClass('array1, array2');
			if(i % 2 == 0) {
				$(el).addClass('array2');
			}
			else {
				$(el).addClass('array1');
			}
		});
 
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 1 week ago #88109 by snieuw
snieuw replied the topic: Hide empty rows of a Matrix
Thanks a lot, that fixed it! Very glad with the code :) Are there any hints or tutorials out there, on how to get the variables in JS? Tried with firebug, but had no success.

Anyway, works perfect, so thanks a lot

Greetings
Steffen

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!