Tables - Table from Data Set

From Q
Jump to navigation Jump to search

This QScript inserts a Table with row and column variable setsquestions prefilled based on the selected data.

Usage

To use this feature, begin by selecting the variable setsquestions you wish to create tables for and then select Table > Table from Data SetCreate > Tables > Table from Data Set. The first selected variable setquestion will be placed in the rows and the second (if one is provided) will be placed in the columns.

If more than two variable setsquestions are selected, additional tables will be created for the extra variable setsquestions.

How to apply this QScript

  • Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
  • Click on the QScript when it appears in the QScripts and Rules section of the search results.

OR

  • Select Automate > Browse Online Library.
  • Select this QScript from the list.

Customizing the QScript

This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.

Customizing QScripts in Q4.11 and more recent versions

  • Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
  • Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
  • Press Edit a Copy (bottom-left corner of the preview).
  • Modify the JavaScript (see QScripts for more detail on this).
  • Either:
    • Run the QScript, by pressing the blue triangle button.
    • Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.

Customizing QScripts in older versions

  • Copy the JavaScript shown on this page.
  • Create a new text file, giving it a file extension of .QScript. See here for more information about how to do this.
  • Modify the JavaScript (see QScripts for more detail on this).
  • Run the file using Automate > Run QScript (Macro) from File.

JavaScript

includeWeb('QScript Utility Functions');  // for inDisplayr()
includeWeb('QScript Selection Functions');// for getAllUserSelections()

let displayr = inDisplayr();
let selected = getAllUserSelections().selected_questions;
let page;

if (!displayr)
    page = project.report;
else {
    page = project.currentPage();
    if (page == null)
        page = project.report.appendPage('Blank');
}

if (selected.length === 0) {
    page.appendTable();
} else {
    let row_vars = selected.filter(function(q,i){ return i % 2 === 0; });
    let column_vars = selected.filter(function(q,i){ return i % 2 === 1; });
    let top_offset = 0;
    let left_offset = 0;
    let table;
    let row_question;
    let column_question;
    while (row_vars.length > 0){
        row_question = row_vars.shift();
        column_question = column_vars.shift();
        table = page.appendTable();
        table.primary = row_question;
        if (column_question !== undefined)
            table.secondary = column_question;
        table.left += left_offset;
        table.top += top_offset;
        left_offset += 15;
        top_offset += 15;
    }
    if (Q.fileFormatVersion() > 8.65)
        project.report.selectedRaw([table]);
}

See also

See Also

* Basic Tables