Welcome, Guest
Username: Password: Remember me

TOPIC: Hide empty rows of a Matrix

Hide empty rows of a Matrix 1 year 11 months ago #87952

  • snieuw
  • snieuw's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
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:
The administrator has disabled public write access.

Re: Hide empty rows of a Matrix 1 year 11 months ago #88064

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4293
  • Thank you received: 810
  • Karma: 373
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Hide empty rows of a Matrix 1 year 11 months ago #88067

  • snieuw
  • snieuw's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
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:
The administrator has disabled public write access.

Re: Hide empty rows of a Matrix 1 year 11 months ago #88087

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4293
  • Thank you received: 810
  • Karma: 373
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Hide empty rows of a Matrix 1 year 11 months ago #88109

  • snieuw
  • snieuw's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
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
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.111 seconds
Donation Image