Welcome to the LimeSurvey Community Forum

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

Array - adding column

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 8 months ago #229664 by boshra.m
Array - adding column was created by boshra.m
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Cloud Version 5.3.19
Own server or LimeSurvey hosting: Hosting
Survey theme/template: Fruity
==================
Hello,

I have a challenging question (perhaps). 

I was wondering if it was possible to add an extra column to an array style question?

Below I have attached an example of what I am thinking about. Having the shaded items repeated or floating, I'll test them both out. With the added column on the very left hand side.  

Thank you. 

 
The following user(s) said Thank You: qiangqi

Please Log in to join the conversation.

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 8 months ago #229949 by boshra.m
Replied by boshra.m on topic Array - adding column
Hello,

This is where my thought process has come from. I have attached an image below and what I have for the code. I havent addedd the corresponding multiple short text code or the question right after to show what I intend to do.

Thank you,

Boshra

<script type="text/javascript" charset="utf-8">
     $(document).on('ready pjax:scriptcomplete',function(){
         // Identify the questions
    var qArrayID = {QID};
    var qArray = $('#question'+qArrayID);
    var qMultiText = qArray.nextAll('.multiple-short-txt:eq(0)');
 
              // Hide the multi-short-text question
    $(qMultiText).hide();
 
    var tableWidth = $('table.questions-list:eq(0)', qArray).width();
    var answerWidth = $('col.ls-col-odd:eq(0)', qArray).width();
    var answerWidthPercent = (answerWidth/tableWidth)*100;
    var answersLength = $('col.ls-col-odd, col.ls-col-even', qArray).length;
    var answerWidthPercent2 = (answerWidthPercent*answersLength)/(answersLength+1)
    $('table.questions-list col', qArray).removeAttr('width');
    $('table.questions-list col:not(.col-answers)', qArray).css('width', 'auto');
      $('table.questions-list thead tr', qArray).append( '<th class="answer-text inserted-column-label" /></th>');
      $('table.questions-list thead tr th.answer-text.inserted-column-label', qArray).css('width','30%');
    $('tr.answers-list', qArray).each(function(i) {
      $(this).append('<td class="answer-item text-item">\
      </td>\
      ');
    });
    // Load the column label for the text inputs
    $('.inserted-column-label:eq(0)', qArray).text($('.ls-label-question', qMultiText).text());
    $('.text-item', qArray).append('<label class="ls-label-xs-visibility">'+$('.ls-label-question', qMultiText).text()+'</label>');
    // Loop through the multi-short-text sub-questions
    $('li.answer-item', qMultiText).each(function(i) {
      // Move the text inputs into the array
      $('input[type="text"]', this).appendTo($('tr.answers-list:eq('+i+') .text-item', qArray));
    });
  });
</script><script type="text/javascript" charset="utf-8">    
    $(document).on('ready pjax:scriptcomplete',function(){
 
        // Identify this question
        var thisQuestion = $('#question{QID}');
 
        // Insert header text
        var insertedText = "wordswordswordswords";
        $('table.subquestion-list thead tr:last td:first', thisQuestion).addClass('inserted-header').append(insertedText);
    });
</script>
<style type="text/css">td.inserted-header {
    font-weight: bold;
    text-align: left;
    vertical-align: middle !important;
    font-style: italic;
}
</style>
 
Attachments:

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 8 months ago #229951 by tpartner
Replied by tpartner on topic Array - adding column
I am not able to give a full example now but you can start by changing all instances of ".append" to ".prepend".

Then, looking at the example above, you may want to add some rowspan attributes to the inserted cells.

- www.w3schools.com/tags/att_td_rowspan.asp

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: qiangqi

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose