Indenting Rows in a Table

From Q
Jump to navigation Jump to search

This example uses JavaScript to indent any rows in a table which do not contain the word "NET".

form.setSummary("Indent row labels");
var indent_string = "  - "; 
var row_labels = table.rowLabels;
var new_row_labels = row_labels
                        .map(function (str) {
                            if (str.indexOf("NET") > -1)
                                return str;
                            else
                                return indent_string + str;
                        });
table.rowLabels = new_row_labels;

This produces a result which looks like this:

PrefColaIndentLabels.PNG

Note that:

  • The indentation is specified by indent_string in the second line. In this case it uses two spaces, followed by a dash and another space. If you want to use a different indentation then you can change this line.
  • The code checks for "NET", and so is specific to the layout of your table and your choice for how to label things which should not be indented.

See also