Skip to main content
Advanced Survey documentation

Customize survey answer lists with JavaScript and CSS

Each survey accepts its own JavaScript and CSS code. This example hides some columns of the answers list and changes the order of others.

Last updated: .

Hide and reorder the columns of the answers list

The code:

$(function () {
  // Column number to move: column number to move it before
  const colToMoveFromBeforeCol = {
    9: 8,
    7: 5,
  };
  // Column numbers to hide
  const colToRemove = [0, 1, 2];
  $("#survey-answers-list tr").each(function () {
    const $thisRow = $(this);
    Object.entries(colToMoveFromBeforeCol).forEach(([fromNb, toNb]) => {
      const $fromCell = $thisRow.find("td, th").eq(fromNb);
      const $toCell = $thisRow.find("td, th").eq(toNb);
      if ($fromCell.length && $toCell.length) {
        $fromCell.detach().insertBefore($toCell);
      }
    });
    colToRemove.forEach(colNb => {
      $thisRow.find("td, th").eq(colNb).hide();
    });
  });
});

Add it in the advanced settings of the survey:

JavaScript field in the advanced settings of the survey

Before:

Answers list with all its columns, before the code

After:

Answers list with columns hidden and reordered, after the code

Read next

Try HumHub with your own content

A hosted community in two minutes, all paid CUZY modules included, no card asked. Keep everything when you subscribe.

Loading...