How to add a column with the row numbers to a bipolar matrix question? | XM Community
Skip to main content

Hi everyone,
I would like to add an identifier column with the row number to a bipolar matrix question with two choices. In specific, I would like to add a column with the # Decision situation 1 - 10 in front of the the description of Lottery A. Ideally, I would also like to add a header column to each side, stating Lottery A / Lottery B, so the labels become A / B.
This is my premier in this forum and I hope someone has a nice idea.
Cheers

image.png

It took me a day to figure it out, but I wrote a code that provided me with what I wanted. I thought I'd share it i) to get feedback on my very first JS code and ii) to potentially help others with the same problem.
This is what it looks like now: I added a column in front of the bipolar matrix and I added headers for both statements.
image.pngjQuery("#"+this.questionId + " tr").prepend(" ");

var lableN = jQuery("#"+this.questionId+" td:eq(0)");
lableN.css("text-align","padding-right");
lableN.css("fontWeight","bold");
lableN.html("Decision Situation");


var lableA = jQuery("#"+this.questionId+" td:eq(1)");
lableA.css("text-align","padding-right");
lableA.css("fontWeight","bold");
lableA.html("Lottery A");


var lableB = jQuery('tbody tr:eq(0)').find('td:last-child').css({fontWeight: "bold"}).after('Lottery B');

jQuery("#"+this.questionId + " tr:eq(2)"   + " td:eq(0)").css({fontWeight: "bold"}).text('1');
jQuery("#"+this.questionId + " tr:eq(3)"   + " td:eq(0)").css({fontWeight: "bold"}).text('2');
jQuery("#"+this.questionId + " tr:eq(4)"   + " td:eq(0)").css({fontWeight: "bold"}).text('3');
jQuery("#"+this.questionId + " tr:eq(5)"   + " td:eq(0)").css({fontWeight: "bold"}).text('4');
jQuery("#"+this.questionId + " tr:eq(6)"   + " td:eq(0)").css({fontWeight: "bold"}).text('5');
jQuery("#"+this.questionId + " tr:eq(7)"   + " td:eq(0)").css({fontWeight: "bold"}).text('6');
jQuery("#"+this.questionId + " tr:eq(8)"   + " td:eq(0)").css({fontWeight: "bold"}).text('7');
jQuery("#"+this.questionId + " tr:eq(9)"   + " td:eq(0)").css({fontWeight: "bold"}).text('8');
jQuery("#"+this.questionId + " tr:eq(10)" + " td:eq(0)").css({fontWeight: "bold"}).text('9');
jQuery("#"+this.questionId + " tr:eq(11)" + " td:eq(0)").css({fontWeight: "bold"}).text('10');


I realised that lable B is visible in the preview in the edit mode, but not in the "preview" mode in the separate tab. Any ideas why that's the case?


Ok, this thread turns into a monologue, but maybe it helps someone later 😃
Changed the code for label B following an advice in another thread
jQuery("#"+this.questionId+" tr.ColumnLabelHeader").append("Lottery B");


I am trying to do this exact thing, so I appreciate your monologue!


Leave a Reply