# Class GridLayout

GoJS® Diagramming Components
version 3.0.7
by Northwoods Software®

#### Hierarchy

- Layout
  - GridLayout

This simple layout places all of the Parts in a grid-like arrangement, ordered, spaced apart, and wrapping as needed. It ignores any Links connecting the Nodes being laid out. There are many samples that use GridLayout. Every Palette uses a GridLayout by default.

If you want to experiment interactively with most of the properties, try the Grid Layout sample. See samples that make use of GridLayout in the samples index.

By default this layout will sort all of the Parts alphabetically (comparing Part.text values, respecting case) and position them left-to-right, separated by spacing`.width`, until they do not fit in the current row. At that time it starts a new row, separated from the previous row by spacing`.height`. There is a uniform cell size equal to the maximum Part width (plus spacing width) and the maximum part height (plus spacing height). At least one part is placed in each row, even if the part by itself is wider than the wrapping width.

You can specify values for the cellSize `width` and `height`. If a part is wider than the cell size, it spans more than one cell in the row.

When the value of wrappingWidth is set to `NaN`, as it is by default, the value of Layout.isViewportSized will be set to true. This causes the layout to be performed again automatically as the viewport changes size. You can also specify a real number value for the wrappingWidth, which will be used instead of the diagram's viewport width, to control when each row is considered "full".

You can also set wrappingColumn to limit the number of items in each row. By default wrappingColumn is `NaN`, meaning that there is no limit on the number of items in any one row. Both the wrappingWidth and the wrappingColumn are respected when deciding when to wrap to the next row.

This layout is sufficiently simple that it does not use a LayoutNetwork.

#####
Index

### Constructors

constructor

### Accessors

alignment
arrangement
cellSize
comparer
sorting
spacing
wrappingColumn
wrappingWidth

### Methods

doLayout

### Properties

Ascending
Descending
Forward
LeftToRight
Location
Position
Reverse
RightToLeft

#####
Inherited Index

### Accessors

Layout.arrangementOrigin
Layout.boundsComputation
Layout.diagram
Layout.group
Layout.isInitial
Layout.isOngoing
Layout.isRealtime
Layout.isRouting
Layout.isValidLayout
Layout.isViewportSized
Layout.network

### Methods

Layout.collectParts
Layout.commitLayout
Layout.copy
Layout.createNetwork
Layout.getLayoutBounds
Layout.initialOrigin
Layout.invalidateLayout
Layout.makeNetwork
Layout.updateParts

## Constructors

### constructor

- new GridLayout(init?: Partial<GridLayout>): GridLayout

- Constructs a GridLayout with no Layout.network and with no owning Layout.diagram.

  #### Parameters

  - ##### `Optional` init: Partial<GridLayout>

    Optional initialization properties.

  #### Returns GridLayout

## Accessors

### alignment
: GridAlignment

- Gets or sets whether the Part.location or the position should be used to arrange each part.

  The default value is GridAlignment.Location -- the Part.locations will be aligned in a grid.

### arrangement
: GridArrangement

- Gets or sets how to arrange the parts. Must be a GridArrangement value.

  The default value is GridArrangement.LeftToRight.

### cellSize
: Size

- Gets or sets the minimum part size by which each part is positioned in the grid.

  The default value is NaN x NaN. The units are in document coordinates.

  When the cell size is smaller than a part, the part will occupy more than one cell. This allows parts to be positioned closer to each other, but then variations in part sizes may cause them not to be aligned in perfect rows or columns.

### comparer
: ((a: Part, b: Part) => number)

- Gets or sets the comparison function used to sort the parts.

  The default value is a case-insensitive alphabetic comparison using the Part.text property of each part.

        $(go.GridLayout,
          {
            sorting: go.GridSorting.Ascending,
            comparer: (pa, pb) => {
              const da = pa.data;
              const db = pb.data;
              if (da.someProperty < db.someProperty) return -1;
              if (da.someProperty > db.someProperty) return 1;
              return 0;
            }
          }
        )

### sorting
: GridSorting

- Gets or sets what order to place the parts. Must be a GridSorting value.

  The default value is GridSorting.Ascending.

### spacing
: Size

- Gets or sets the minimum horizontal and vertical space between parts.

  The default value is 10 x 10. The units are in document coordinates.

### wrappingColumn
: number

- Gets or sets the maximum number of items that the layout will arrange in a single row.

  The default is NaN, meaning not to limit the number of columns. 1 is a common value to produce a single column of parts. The value must be positive or NaN.

  When Diagram.initialAutoScale or Diagram.autoScale are not None, it is common to set wrappingColumn and wrappingWidth to large values -- whatever seems reasonable given the number and size of the parts that will be laid out and the size of the viewport.

### wrappingWidth
: number

- Gets or sets the width beyond which the layout will start a new row.

  The default is NaN, meaning to use the width of the diagram's panel's viewport. Infinity is a common value to produce a single row of parts, unless limited by wrappingColumn. The value must be positive or NaN.

  If the new value is NaN, Layout.isViewportSized will be set to true. When Diagram.initialAutoScale or Diagram.autoScale are not None, it is common to set wrappingColumn and wrappingWidth to large values -- whatever seems reasonable given the number and size of the parts that will be laid out and the size of the viewport.

## Methods

### `Override` doLayout

- doLayout(coll: Diagram | Iterable<Part> | Group): void

- Assign the positions of the parts, ignoring any links.

  #### Parameters

  - ##### coll: Diagram | Iterable<Part> | Group

    A Diagram or a Group or a collection of Parts.

  #### Returns void

## Properties

### `Static` `Readonly` Ascending

`deprecated`

See GridSorting.Ascending.

### `Static` `Readonly` Descending

`deprecated`

See GridSorting.Descending.

### `Static` `Readonly` Forward

`deprecated`

See GridSorting.Forwards.

### `Static` `Readonly` LeftToRight

`deprecated`

See GridArrangement.LeftToRight.

### `Static` `Readonly` Location

`deprecated`

See GridAlignment.Location.

### `Static` `Readonly` Position

`deprecated`

See GridAlignment.Position.

### `Static` `Readonly` Reverse

`deprecated`

See GridSorting.Reverse.

### `Static` `Readonly` RightToLeft

`deprecated`

See GridArrangement.RightToLeft.

Copyright © 1998-2024 by Northwoods Software Corporation.