Google Apps Script

Class Grid

A rectangular grid that can contain text, html, or a child widget within its cells. It must be resized explicitly to the desired number of rows and columns.

Here is an example of how to use this widget:

 
function doGet() {
   var app = UiApp.createApplication();
   app.add(app.createGrid(3, 3)
       .setBorderWidth(1)
       .setCellSpacing(10)
       .setCellPadding(10)
       .setText(0, 0, "X")
       .setText(1, 1, "X")
       .setText(2, 2, "X")
       .setText(0, 1, "O")
       .setText(0, 2, "O")
       .setStyleAttribute(0, 0, "color", "red")
       .setStyleAttribute(1, 1, "color", "red")
       .setStyleAttribute(2, 2, "color", "red")
       .setStyleAttribute(0, 1, "color", "blue")
       .setStyleAttribute(0, 2, "color", "blue"));
   return app;
 }
 

Internally, UiApp widgets are built on top of the Google Web Toolkit, and it can sometimes be helpful to look at the GWT documentation directly. You can find the Grid documentation here.

Methods

MethodReturn typeBrief description
addClickHandler(handler)GridAdd a handler for click events.
addStyleDependentName(styleName)GridSets the dependent style name of this Grid.
addStyleName(styleName)GridAdds a style name to this Grid.
clear()GridRemove all widgets from the Grid.
getId()StringReturns the id that has been assigned to this object.
getTag()StringGets the text tag of this Grid.
getType()StringGets the type of this object.
resize(rows, columns)GridResizes the Grid.
setBorderWidth(width)GridSets the border width.
setCellPadding(padding)GridSets the padding within cells.
setCellSpacing(spacing)GridSets the spacing between cells.
setColumnStyleAttribute(column, attribute, value)GridSets a CSS style on a column of this Grid.
setColumnStyleAttributes(column, attributes)GridSets a CSS style on a column of this Grid.
setHeight(height)GridSets the height of this Grid.
setId(id)GridSets the id of this Grid.
setPixelSize(width, height)GridSets the size of this Grid in pixels.
setRowStyleAttribute(row, attribute, value)GridSets a CSS style on a row of this Grid.
setRowStyleAttributes(row, attributes)GridSets a CSS style on a row of this Grid.
setSize(width, height)GridSets the size of this Grid.
setStyleAttribute(row, column, attribute, value)GridSets a CSS style on a cell of this Grid.
setStyleAttribute(attribute, value)GridSets one of this Grid's style attributes to a new value.
setStyleAttributes(row, column, attributes)GridSets a CSS style on a cell of this Grid.
setStyleAttributes(attributes)GridSets this Grid's style attributes.
setStyleName(styleName)GridSets the style name of this Grid.
setStylePrimaryName(styleName)GridSets the primary style name of this Grid.
setTag(tag)GridSets the text tag of this Grid.
setText(row, column, text)GridSets the contents of a given cell to the given text.
setTitle(title)GridSets the hover title of this Grid.
setVisible(visible)GridSets whether this Grid is visible.
setWidget(row, column, widget)GridSets the widget in a given cell.
setWidth(width)GridSets the width of this Grid.

Detailed documentation

addClickHandler(handler)

Add a handler for click events.

Note that you can have multiple handlers for the same event on the same widget. They will be called in the order that they were added to the widget, although ServerHandlers may appear to happen simultaneously.

The handler passes back some information to the server about what happened. This information can be accessed as follows:

 
function doGet() {
   var app = UiApp.createApplication();
   var button = app.createButton("a button");
   var handler = app.createServerHandler("handlerFunction");
   button.addClickHandler(handler);
   app.add(button);
   return app;
 }

 function handlerFunction(eventInfo) {
   var parameter = eventInfo.parameter;
   // the type of event, in this case "click".
   var eventType = parameter.eventType;
   // the id of the widget that fired this event.
   var source = parameter.source;
   // mouse x and y position relative to the widget that fired the event.
   var x = parameter.x;
   var y = parameter.y;
   // mouse x and y position within the browser window's client area.
   var clientX = parameter.clientX;
   var clientY = parameter.clientY;
   // mouse x and y position within the user's display.
   var screenX = parameter.screenX;
   var screenY = parameter.screenY;
   // the mouse button used. Left is 1, right is 2, and middle is 4.
   var button = parameter.button;
   // whether the various modifier keys were also pressed (true or false)
   var shift = parameter.shift;
   var alt = parameter.alt;
   var ctrl = parameter.ctrl;
   var meta = parameter.meta;
 }
 
In addition, the values of certain widgets can be sent up with the event as well, as "callback elements." See the documentation of ServerHandler for more information.

Parameters

NameTypeDescription
handlerHandlerthe handler to execute when the event occurs. This can be a ClientHandler or a ServerHandler.

Return

Grid — the Grid itself, useful for chaining.


addStyleDependentName(styleName)

Sets the dependent style name of this Grid.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

Grid — the Grid itself, useful for chaining.


addStyleName(styleName)

Adds a style name to this Grid.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

Grid — the Grid itself, useful for chaining.


clear()

Remove all widgets from the Grid.

Return

Grid — the Grid itself, useful for chaining.


getId()

Returns the id that has been assigned to this object.

This can be used in conjunction with app.getElementById() to retrieve a reference to this object.

Return

String — the id that has been assigned to this object


getTag()

Gets the text tag of this Grid.

Return

String — the text tag.


getType()

Gets the type of this object.

Return

String — the object type


resize(rows, columns)

Resizes the Grid.

Parameters

NameTypeDescription
rowsIntegerthe new number of rows.
columnsIntegerthe new number of columns.

Return

Grid — the Grid itself, useful for chaining.


setBorderWidth(width)

Sets the border width.

Parameters

NameTypeDescription
widthIntegerthe border width, in pixels.

Return

Grid — the Grid itself, useful for chaining.


setCellPadding(padding)

Sets the padding within cells.

Parameters

NameTypeDescription
paddingIntegerthe padding, in pixels.

Return

Grid — the Grid itself, useful for chaining.


setCellSpacing(spacing)

Sets the spacing between cells.

Parameters

NameTypeDescription
spacingIntegerthe spacing, in pixels.

Return

Grid — the Grid itself, useful for chaining.


setColumnStyleAttribute(column, attribute, value)

Sets a CSS style on a column of this Grid.

Parameters

NameTypeDescription
columnIntegerthe column number.
attributeStringthe CSS attribute, in camelCase. ("fontSize", not "font-size").
valueStringthe CSS value

Return

Grid — the Grid itself, useful for chaining.


setColumnStyleAttributes(column, attributes)

Sets a CSS style on a column of this Grid.

Parameters

NameTypeDescription
columnIntegerthe column number.
attributesObjectthe CSS attributes and values to set.

Return

Grid — the Grid itself, useful for chaining.


setHeight(height)

Sets the height of this Grid.

Parameters

NameTypeDescription
heightStringthe new height in any CSS unit such as "10px" or "50%".

Return

Grid — the Grid itself, useful for chaining.


setId(id)

Sets the id of this Grid.

Parameters

NameTypeDescription
idStringthe new id, which can be used to retrieve the Grid from app.getElementById(id).

Return

Grid — the Grid itself, useful for chaining.


setPixelSize(width, height)

Sets the size of this Grid in pixels.

Parameters

NameTypeDescription
widthIntegerthe new width in pixels.
heightIntegerthe new height in pixels.

Return

Grid — the Grid itself, useful for chaining.


setRowStyleAttribute(row, attribute, value)

Sets a CSS style on a row of this Grid.

Parameters

NameTypeDescription
rowIntegerthe row number.
attributeStringthe CSS attribute, in camelCase. ("fontSize", not "font-size").
valueStringthe CSS value

Return

Grid — the Grid itself, useful for chaining.


setRowStyleAttributes(row, attributes)

Sets a CSS style on a row of this Grid.

Parameters

NameTypeDescription
rowIntegerthe row number.
attributesObjectthe CSS attributes and values to set.

Return

Grid — the Grid itself, useful for chaining.


setSize(width, height)

Sets the size of this Grid.

Parameters

NameTypeDescription
widthStringthe new width in any CSS unit such as "10px" or "50%".
heightStringthe new height in any CSS unit such as "10px" or "50%".

Return

Grid — the Grid itself, useful for chaining.


setStyleAttribute(row, column, attribute, value)

Sets a CSS style on a cell of this Grid.

Parameters

NameTypeDescription
rowIntegerthe row of the cell.
columnIntegerthe column of the cell.
attributeStringthe CSS attribute, in camelCase. ("fontSize", not "font-size").
valueStringthe CSS value

Return

Grid — the Grid itself, useful for chaining.


setStyleAttribute(attribute, value)

Sets one of this Grid's style attributes to a new value. Valid attributes are listed here; the values for each attribute are the same as those available in CSS style sheets.

 
// Change the widget's background to black and text color to green.
 widget.setStyleAttribute("background", "black")
     .setStyleAttribute("color", "green");
 

Parameters

NameTypeDescription
attributeStringthe CSS attribute, in camel-case ("fontSize", not "font-size"), as listed here
valueStringthe CSS value

Return

Grid — the Grid itself, useful for chaining.


setStyleAttributes(row, column, attributes)

Sets a CSS style on a cell of this Grid.

Parameters

NameTypeDescription
rowIntegerthe row of the cell.
columnIntegerthe column of the cell.
attributesObjectthe CSS attributes and values to set.

Return

Grid — the Grid itself, useful for chaining.


setStyleAttributes(attributes)

Sets this Grid's style attributes. This is a convenience method that is equivalent to calling setStyleAttribute with every key/value pair in the attributes object. Valid attributes are listed here; the values for each attribute are the same as those available in CSS style sheets.

 
// Change the widget's background to black and text color to green.
 widget.setStyleAttributes({background: "black", color: "green"});
 

Parameters

NameTypeDescription
attributesObjectan object of key/value pairs for the CSS attributes and values to set; valid attributes are listed here

Return

Grid — the Grid itself, useful for chaining.


setStyleName(styleName)

Sets the style name of this Grid.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

Grid — the Grid itself, useful for chaining.


setStylePrimaryName(styleName)

Sets the primary style name of this Grid.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

Grid — the Grid itself, useful for chaining.


setTag(tag)

Sets the text tag of this Grid.

Parameters

NameTypeDescription
tagStringthe new text tag, which can be anything you wish to store with the widget.

Return

Grid — the Grid itself, useful for chaining.


setText(row, column, text)

Sets the contents of a given cell to the given text. This will remove any widget in the cell if one was there.

Parameters

NameTypeDescription
rowIntegerthe row of the cell.
columnIntegerthe column of the cell.
textStringthe text to insert.

Return

Grid — the Grid itself, useful for chaining.


setTitle(title)

Sets the hover title of this Grid.

Not all browsers will show this.

Parameters

NameTypeDescription
titleStringthe hover title.

Return

Grid — the Grid itself, useful for chaining.


setVisible(visible)

Sets whether this Grid is visible.

Parameters

NameTypeDescription
visibleBooleanwhether this Grid should be visible or not.

Return

Grid — the Grid itself, useful for chaining.


setWidget(row, column, widget)

Sets the widget in a given cell. A cell can contain at most one widget.

Parameters

NameTypeDescription
rowIntegerthe row of the cell.
columnIntegerthe column of the cell.
widgetWidgetthe widget to insert.

Return

Grid — the Grid itself, useful for chaining.


setWidth(width)

Sets the width of this Grid.

Parameters

NameTypeDescription
widthStringthe new width in any CSS unit such as "10px" or "50%".

Return

Grid — the Grid itself, useful for chaining.

Deprecated methods

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.