Welcome, Guest
Username: Password: Remember me

TOPIC: Hiding table column (header)

Hiding table column (header) 7 months 1 week ago #107404

  • blacknail
  • blacknail's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 30
  • Thank you received: 1
  • Karma: 0
Hello all again,

I'm wondering how can I hide a column in an array question (in this case, the first one, which corresponds to the subquestions' column - please see attached screenshot). Since I want that column to be hidden AND to not take up any space, hiding the columns' borders is not an option. I've tried two different paths, both aren't working:

1) First, I've tried to use the "display:none;" property/value:
<script charset="utf-8" script="" type="text/javascript">
    $(document).ready(function ()
    {
        $("table.question thead td").css("display", "none");
        $("table.question tbody th").css("display", "none");
    });
</script>

The result, however, is that the entire table disappears, instead of the first column.

2) Then, I've tried also a solution found here:
<script charset="utf-8" script="" type="text/javascript">
$(document).ready(function ()
    {
        // Hide the first column
        $('#question'+qID+' th.header_answer_text, #question'+qID+' th.answertext').hide();
    });
</script>

Here, the result is that (apparently) nothing happens, and so the table doesn't change.

(I'm using Version 2.05+ Build 140320)

What can I be possibly doing wrong?

Best regards.



preocupacao_ambiental.png
Last Edit: 7 months 1 week ago by blacknail. Reason: missing version number
The administrator has disabled public write access.

Hiding table column (header) 7 months 1 week ago #107407

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4360
  • Thank you received: 827
  • Karma: 381
You may have another table with class "question" in your template.

To be more specific, try this in the array question source:
<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question'+{QID}+'');
 
		$('table.subquestions-list thead td', thisQuestion).hide();   
		$('table.subquestions-list tr.answers-list th', thisQuestion).hide();   
		$('table.subquestions-list col', thisQuestion).css('width', 'auto');
	});
</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.
The following user(s) said Thank You: blacknail

Hiding table column (header) 7 months 1 week ago #107408

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4360
  • Thank you received: 827
  • Karma: 381
Or better yet, here's a column-specific approach:
<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function() { 
 
		// Identify this question
		var thisQuestion = $('#question'+{QID}+'');
 
		// Add some column-specific classes
		$('table.subquestions-list tr', thisQuestion).each(function(i){
			$('> *', this).each(function(i){
				$(this).addClass('column-'+(i+1));
			});
		});
 
		// Hide all column-1 elements
		$('.column-1', thisQuestion).hide();   
		$('table.subquestions-list col', thisQuestion).css('width', 'auto');
 
	});
</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.
The following user(s) said Thank You: blacknail

Hiding table column (header) 7 months 1 week ago #107409

  • david2013
  • david2013's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 30
  • Thank you received: 3
  • Karma: 2
In advance setting, set the first column width to 0
The administrator has disabled public write access.
The following user(s) said Thank You: blacknail

Hiding table column (header) 7 months 1 week ago #107410

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4360
  • Thank you received: 827
  • Karma: 381
Yeah, good tip rot the first column David.
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.
The following user(s) said Thank You: blacknail

Hiding table column (header) 7 months 1 week ago #107440

  • blacknail
  • blacknail's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 30
  • Thank you received: 1
  • Karma: 0
Thanks for your quick and kind answers, tpartner and David. Both tparner's suggestions produced the same result: they indeed hid the first column, but the second one (which is now the first one viisible), got it's width messed up, just like the last one (please see the attached screenshot, "preocupacao_ambiental_3.png"). I looked at the code but couldn't find something "suspicious" that could led to this results - maybe previous changes made by myself to the template?

Concerning David's solution, it produced the result portraited in the "preocupacao_ambiental_2.png" screenshot (also attached to this post), i.e. it reduced dramatically the width of the first column, although it is still present there.

So, if you can find something that I can improve in (at least) one of tpartner's solutions, it would be great. Otherwise, I will take David's advice and just hide the first column borders, and it will suffice.

Thanks again for all your helpful comments.


preocupacao_ambiental_2.png


preocupacao_ambiental_3.png
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.160 seconds
Donation Image