Automatically Applying Filters to Some Categories in a Banner

From Q
Jump to navigation Jump to search

This example can be run using C:\Program Files\Q\Examples]Phone 1.Q (this file may be in a different place on your computer). Note in this example that:

  • The filter variable that is automatically applied is not tagged as a filter and is not available in the Filter drop-down menu.
  • This example only changes the values in the cells of the table. It will not update any statistics selected by Statistics - Below.

This script will cause significance results to be displayed incorrectly. Please read Caveats for Table JavaScript before using this script.

// Finds any columns in the span 'Gender' and applies the filter with variable name 'Ageunder35' to them.
var spans = table.columnSpans;
var columns = null;
for (var i=0; i<spans.length; i++)
  if (spans[i].label == 'Gender')
      columns = spans[i].indices;
var filtered_table = calculateTable(table.blue, table.brown,['Ageunder35'], '!UseQWeight');
var stats = table.statistics; //gets the names of the statistics shown on the table
if (columns != null)
    for (var i = 0; i < columns.length; i++) {
        var column = columns[i];
        // Copy the weighted statistics for the column to the current table .
        for (var stat = 0; stat < stats.length; stat++) {
            var filtered_values = filtered_table.get(stats[stat]);
            var main_values = table.get(stats[stat]);
            for (var row = 0; row < table.numberRows; row++)
                main_values[row][column] = filtered_values[row][column];
            table.set(stats[stat], main_values);// Set the altered values to the main table.
        }
}

See also