Tables - Table from Data Set
Jump to navigation
Jump to search
This QScript inserts a Table with row and column questions prefilled based on the selected data.
Usage
To use this feature, begin by selecting the questions you wish to create tables for and then select Create > Tables > Table from Data Set. The first selected question will be placed in the rows and the second (if one is provided) will be placed in the columns.
If more than two questions are selected, additional tables will be created for the extra questions.
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
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');
}
let table;
if (selected.length === 0) {
table = 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 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.setSelectedRaw([table]);
See also
- QScript for more general information about QScripts.
- QScript Examples Library for other examples.
- Online JavaScript Libraries for the libraries of functions that can be used when writing QScripts.
- QScript Reference for information about how QScript can manipulate the different elements of a project.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.