Modifying the Whole Table or Plot - Showing A Range Of Rows

From Q
Jump to: navigation, search

This Rule allows you to select a range of rows to show on a table or chart (e.g., rows 5 through 10). It can be used where you have a large table and wish to export it to PowerPoint as multiple separate tables. In this case you should create the same table multiple times in Q, and then set this rule separately on each table with sequential ranges of rows.

How to apply this rule

For the first time in a project

  • Select the table(s)/chart(s) that you wish to apply the rule to.
  • Start typing the name of the Rule into the Search features and data box in the top right of the Q window.
  • Click on the Rule when it appears in the QScripts and Rules section of the search results.

OR

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

Additional applications of the rule

  • Select a table or chart that has the rule and any table(s)/chart(s) that you wish to apply the rule to.
  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to apply.
  • Click on the Apply drop-down and choose your desired option.
  • Check New items to have it automatically applied to new items that you create. Use Edit > Project Options > Save as Template to create a new project template that automatically uses this rule.

Removing the rule

  • Select the table(s)/chart(s) that you wish to remove the rule from.
  • Press the Rules tab (bottom-right corner).
  • Press Apply next to the rule you wish to remove and choose the appropriate option.

How to modify the rule

  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to modify.
  • Click Edit Rule and make the desired changes. Alternatively, you can use the JavaScript below to make your own rule (see Customizing Rules).

JavaScript

You can find a detailed discussion of this code at Creating a Custom Rule.

includeWeb("Table JavaScript Utility Functions");
 
// Heading for the form
form.setHeading('Selecting a range of rows to show');
 
// Creating input for user to specify number of rows
var number_label = form.newLabel('First row number to retain:'); //creating the phrase 'Number of rows:' 
var numeric_up_down = form.newNumericUpDown('threshold'); //creating a control where a user can enter a number.
numeric_up_down.lineBreakAfter = true;
numeric_up_down.setDefault(1);// specifying the default number of rows to be shown
numeric_up_down.setIncrement(1); // specifying that the user must enter whole numbers.
numeric_up_down.setMinimum(0); // preventing the user from having tables with less than 0 rows (not 1, as a user may wish to only specify the brands)
var number_label1 = form.newLabel('Last row number to retain:'); 
var numeric_up_down1 = form.newNumericUpDown('threshold1'); 
numeric_up_down1.lineBreakAft1er = true;
numeric_up_down1.setDefault(1);
numeric_up_down1.setIncrement(1);
numeric_up_down1.setMinimum(0); 
var control_array = [number_label, numeric_up_down,number_label1, numeric_up_down1];
form.setInputControls(control_array);
 
// There is currently a bug with removing rows from dates crossed with 2D questions
if (table.blueQuestion.questionType == "Date"
	&& ["Pick Any - Grid", "Number - Grid", "Pick One - Multi"].indexOf(table.brownQuestion.questionType) > -1)
	form.ruleNotApplicable("this rule cannot be applied for Date questions crossed with " + table.brownQuestion.questionType + " questions.");
 
// Extracting the rows to be used.
var first_row = numeric_up_down.getValue();
var last_row = numeric_up_down1.getValue();
 
// Validating inputs.
if (last_row > table.numberRows) 
    form.ruleNotApplicable("The specified last row exceeds the number of rows in the table");
if (first_row > last_row) 
    form.ruleNotApplicable("The specified first row is greater than the specified last row");
 
// Creating a summary
form.setSummary('Show rows ' + first_row + ' to ' + last_row);
 
// Deleting the rows
while (table.numberRows > last_row)
    deleteRowComplete(table.numberRows - 1);
for (var i = 0; i < first_row - 1; i++)
    deleteRowComplete(0);

See also

Personal tools
Namespaces

Variants
Actions
Navigation
Categories
Toolbox