Repeat Headers in Matrix Table | XM Community
Skip to main content
Solved

Repeat Headers in Matrix Table

  • December 9, 2020
  • 4 replies
  • 1851 views

Hello,
I'm looking to repeat my headers at various intervals within my long Matrix Table. I have seen a Javascript code circling around - but unsure of how to use it, and was hoping to get some help!
For example after question 3, 7, 10, etc. based on how the questions are "grouped" together.

Best answer by ahmedA

Its possible via JS, see if this works for you:
Qualtrics.SurveyEngine.addOnReady(function()
{
    choice_table = this.getChoiceContainer();
    //Numbering starts from 0. So the header is the 0th row, the first statement row 1 etc. 
    //This will create an empty row above statement 4. YOu can change it accordingly. 
    new_row = choice_table.insertRow(4);
    
    //rows[0] refersto the header. 
    // So this takes the header row fills up the empty row just created. 
    new_row.innerHTML = choice_table.rows[0].innerHTML;
});
The code given above, works based on position. So, if you are randomizing you're statements, you will have to figure out where you need to insert your new row. Also, each group is a row, so take that also into account.

4 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • December 9, 2020

  • Author
  • December 10, 2020

Yes - when I add the current functionality in, it doesn't allow to change where the headers are repeated within the survey. I wanted the headers to repeat after/before certain questions and it doesn't allow me to do this. Do you know of anyway this can be done?


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • Answer
  • December 10, 2020

Its possible via JS, see if this works for you:
Qualtrics.SurveyEngine.addOnReady(function()
{
    choice_table = this.getChoiceContainer();
    //Numbering starts from 0. So the header is the 0th row, the first statement row 1 etc. 
    //This will create an empty row above statement 4. YOu can change it accordingly. 
    new_row = choice_table.insertRow(4);
    
    //rows[0] refersto the header. 
    // So this takes the header row fills up the empty row just created. 
    new_row.innerHTML = choice_table.rows[0].innerHTML;
});
The code given above, works based on position. So, if you are randomizing you're statements, you will have to figure out where you need to insert your new row. Also, each group is a row, so take that also into account.


  • Author
  • December 10, 2020

ahmedA Thank you so much!! This worked and was a lifesaver!
Thank you so much!!