Modify Whole Table or Plot - Show a Range of Rows

From Q
Jump to navigation Jump to 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');
let description = form.newLabel("Specify a range of row numbers to keep in the table. The top row is row 1.");
description.lineBreakAfter = true;

// Creating input for user to specify number of rows
let number_label = form.newLabel('First row number to retain:'); //creating the phrase 'Number of rows:' 
let 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)
numeric_up_down.setMaximum(100000);
let number_label1 = form.newLabel('Last row number to retain:'); 
let numeric_up_down1 = form.newNumericUpDown('threshold1'); 
numeric_up_down1.lineBreakAfter = true;
numeric_up_down1.setDefault(1);
numeric_up_down1.setIncrement(1);
numeric_up_down1.setMinimum(0);
numeric_up_down1.setMaximum(100001);  
let control_array = [description, number_label, numeric_up_down,number_label1, numeric_up_down1];
form.setInputControls(control_array);

// Extracting the rows to be used.
let first_row = numeric_up_down.getValue();
let 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 (let i = 0; i < first_row - 1; i++)
    deleteRowComplete(0);

See also