Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Hiding table column (header)

  • blacknail
  • blacknail's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 11 months ago - 9 years 11 months ago #107404 by blacknail
Hiding table column (header) was created by blacknail
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:
Code:
<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 :
Code:
<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.



Last edit: 9 years 11 months ago by blacknail. Reason: missing version number
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago #107407 by tpartner
Replied by tpartner on topic Hiding table column (header)
You may have another table with class "question" in your template.

To be more specific, try this in the array question source:
Code:
<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.
The following user(s) said Thank You: blacknail
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago #107408 by tpartner
Replied by tpartner on topic Hiding table column (header)
Or better yet, here's a column-specific approach:
Code:
<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.
The following user(s) said Thank You: blacknail
The topic has been locked.
More
9 years 11 months ago #107409 by david2013
Replied by david2013 on topic Hiding table column (header)
In advance setting, set the first column width to 0
The following user(s) said Thank You: blacknail
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago #107410 by tpartner
Replied by tpartner on topic Hiding table column (header)
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.
The following user(s) said Thank You: blacknail
The topic has been locked.
  • blacknail
  • blacknail's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 11 months ago #107440 by blacknail
Replied by blacknail on topic Hiding table column (header)
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.




The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose