Google Apps Script

Class StringFilterBuilder

A builder for string filter controls.

A string filter is a simple text input field that lets the user filter data via string matching. Given a column of type string and matching options, this control will filter out the rows that don't match the term that's in the input field.

This example creates a table chart and binds it to a string filter. Using the filter, it is possible to change the table chart to display a subset of its data.

 
function doGet() {
   var app = UiApp.createApplication();
   var sampleData = Charts.newDataTable()
       .addColumn(Charts.ColumnType.STRING, "Month")
       .addColumn(Charts.ColumnType.NUMBER, "Dining")
       .addColumn(Charts.ColumnType.NUMBER, "Total")
       .addRow(["Jan", 60, 520])
       .addRow(["Feb", 50, 430])
       .addRow(["Mar", 53, 440])
       .addRow(["Apr", 70, 410])
       .addRow(["May", 80, 390])
       .addRow(["Jun", 60, 500])
       .addRow(["Jul", 100, 450])
       .addRow(["Aug", 140, 431])
       .addRow(["Sep", 75, 488])
       .addRow(["Oct", 70, 521])
       .addRow(["Nov", 58, 388])
       .addRow(["Dec", 63, 400])
       .build();
       
   var chart = Charts.newTableChart()
       .setDimensions(600, 500)
       .build();
       
   var stringFilter = Charts.newStringFilter()
       .setFilterColumnLabel("Month")
       .setRealtimeTrigger(true)
       .setCaseSensitive(true)
       .setLabel("Filter months shown")
       .build();
   
   var panel = app.createVerticalPanel().setSpacing(10);
   panel.add(stringFilter).add(chart);
   
   // Create a dashboard panel to bind the filter and the chart together.
   var dashboard = Charts.newDashboardPanel()
       .setDataTable(sampleData)
       .bind(stringFilter, chart)
       .build();
       
   dashboard.add(panel);
   app.add(dashboard);
   return app;
 }
 
For more details, see the Gviz documentation.

Methods

MethodReturn typeBrief description
build()ControlBuilds a control.
setCaseSensitive(caseSensitive)StringFilterBuilderSets whether matching should be case sensitive or not.
setDataTable(tableBuilder)StringFilterBuilderSets the data table to use for the control using a DataTableBuilder.
setDataTable(table)StringFilterBuilderSets the control data table, which will be the control's underlying data model.
setFilterColumnIndex(columnIndex)StringFilterBuilderSets the index of the data table column to filter on.
setFilterColumnLabel(columnLabel)StringFilterBuilderSets the label of the data table column to filter on.
setLabel(label)StringFilterBuilderSets the label to display next to the slider.
setLabelSeparator(labelSeparator)StringFilterBuilderSets a separator string appended to the label, to visually separate the label from the category picker.
setLabelStacking(orientation)StringFilterBuilderSets whether the label should display above (vertical stacking) or beside (horizontal stacking) the input field.
setMatchType(matchType)StringFilterBuilderSets whether the control should match exact values only (MatchType.EXACT), prefixes starting from the beginning of the value (MatchType.PREFIX), or any substring (MatchType.ANY).
setRealtimeTrigger(realtimeTrigger)StringFilterBuilderSets whether the control should match any time a key is pressed or only when the input field 'changes' (loss of focus or pressing the Enter key).

Detailed documentation

build()

Builds a control.

Return

Control — a control object, that can be used as a UI element


setCaseSensitive(caseSensitive)

Sets whether matching should be case sensitive or not.

 
// Builds a case insensitive string filter to filter column "Col1".
 var stringFilter = Charts.newStringFilter()
   .setFilterColumnLabel("Col1")
   .setCaseSensitive(false)
   .build();
 

Parameters

NameTypeDescription
caseSensitiveBooleanif true, enables string matching case sensitivity

Return

StringFilterBuilder — this builder, useful for chaining


setDataTable(tableBuilder)

Sets the data table to use for the control using a DataTableBuilder. This is a convenience method for setting the data table without needing to call build().

Parameters

NameTypeDescription
tableBuilderDataTableBuildera data table builder. A new data table will be created instantly as part of this call, so any further updates to the builder won't be reflected in the control.

Return

StringFilterBuilder — this builder, useful for chaining


setDataTable(table)

Sets the control data table, which will be the control's underlying data model.

Parameters

NameTypeDescription
tableDataTableSourcethe data table to use for the control

Return

StringFilterBuilder — this builder, useful for chaining


setFilterColumnIndex(columnIndex)

Sets the index of the data table column to filter on. The values of that column will determine whether or not each row should be filtered. It is mandatory to set either this or the column label using setFilterColumnLabel(columnLabel).

Parameters

NameTypeDescription
columnIndexIntegerthe index of the data table column the filter should operate upon

Return

StringFilterBuilder — this builder, useful for chaining


setFilterColumnLabel(columnLabel)

Sets the label of the data table column to filter on. The values of that column will determine whether or not each row should be filtered. It is mandatory to set either this or a column index using setFilterColumnIndex(columnIndex).

Parameters

NameTypeDescription
columnLabelStringthe label of the column to filter on

Return

StringFilterBuilder — this builder, useful for chaining


setLabel(label)

Sets the label to display next to the slider. If unspecified, the label of the column the control operates on will be used.

Parameters

NameTypeDescription
labelStringthe label to display next to the slider

Return

StringFilterBuilder — this builder, useful for chaining


setLabelSeparator(labelSeparator)

Sets a separator string appended to the label, to visually separate the label from the category picker.

Parameters

NameTypeDescription
labelSeparatorStringthe string to use to separate the label from the category picker

Return

StringFilterBuilder — this builder, useful for chaining


setLabelStacking(orientation)

Sets whether the label should display above (vertical stacking) or beside (horizontal stacking) the input field.

Parameters

NameTypeDescription
orientationOrientationthe orientation of the stacking

Return

StringFilterBuilder — this builder, useful for chaining


setMatchType(matchType)

Sets whether the control should match exact values only (MatchType.EXACT), prefixes starting from the beginning of the value (MatchType.PREFIX), or any substring (MatchType.ANY).

 
// Builds a string filter to filter column "Col1" matching the prefix.
 var stringFilter = Charts.newStringFilter()
   .setFilterColumnLabel("Col1")
   .setMatchType(Charts.MatchType.PREFIX)
   .build();
 

Parameters

NameTypeDescription
matchTypeMatchTypethe string matching type

Return

StringFilterBuilder — this builder, useful for chaining

See also


setRealtimeTrigger(realtimeTrigger)

Sets whether the control should match any time a key is pressed or only when the input field 'changes' (loss of focus or pressing the Enter key).

 
// Builds a string filter to filter column "Col1" that checks the match any time a key is
 // pressed.
 var stringFilter = Charts.newStringFilter()
   .setFilterColumnLabel("Col1")
   .setRealtimeTrigger(true)
   .build();
 

Parameters

NameTypeDescription
realtimeTriggerBooleanif true, sets events to be triggered at real time (when a key is pressed)

Return

StringFilterBuilder — this builder, useful for chaining

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.