Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Hide empty rows of a Matrix

Hide empty rows of a Matrix 1 Jahr 9 Monate her #87952

  • snieuw
  • snieuws Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 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
Anhang:
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Hide empty rows of a Matrix 1 Jahr 9 Monate her #88064

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4119
  • Dank erhalten: 760
  • Karma: 346
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Hide empty rows of a Matrix 1 Jahr 9 Monate her #88067

  • snieuw
  • snieuws Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 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
Anhang:
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Hide empty rows of a Matrix 1 Jahr 9 Monate her #88087

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4119
  • Dank erhalten: 760
  • Karma: 346
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Hide empty rows of a Matrix 1 Jahr 9 Monate her #88109

  • snieuw
  • snieuws Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 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
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.160 Sekunden
Donation Image