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;
const as_output = !displayr || (Q.singleOutputsAreEnabled && Q.singleOutputsAreEnabled());
if (as_output)
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 outputs;
if (selected.every(obj => obj.hasOwnProperty("type") && obj.type === "Question"))
outputs = selected.map(q => ({
primary: q,
secondary: /^Text/.test(q.questionType) ? "RAW DATA" : "SUMMARY"
}));
outputs = outputs.filter(obj => obj.primary.isValid && (typeof obj.secondary === 'string' || !!obj.secondary.isValid))
const n_outputs = outputs.length;
let top_offset = 0;
let left_offset = 0;
for (let i = 0; i < n_outputs; i++) {
table = page.appendTable(as_output);
table.primary = outputs[i].primary;
table.secondary = outputs[i].secondary;
if (!as_output) {
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.