# grid Examples

### Custom column width

A simple but powerful use case for `grid` is controlling the width of columns in your view.&#x20;

With the [`columns`](https://docs.journeyapps.com/reference/build/ui-components/all-ui-components/columns) UI component, you can add any number of columns to your view, however they will all have the same width:

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2FRMWzJRwE1Xx9W1N88RF6%2Fgrid-example-using-columns.png?alt=media&#x26;token=13d9827f-241a-45cc-8a74-415687c5e1f9" alt=""><figcaption><p>Guided work instructions using columns</p></figcaption></figure>

With `grid`, you can also add any number of columns to your view, and you can control the span of each column (i.e. its width) using the [`column-span`](https://docs.journeyapps.com/reference/build/ui-components/all-ui-components/cell#column-span) attribute. This is useful where you want certain components to be larger than others - for example an image or a [3D model](https://docs.journeyapps.com/reference/build/ui-components/all-ui-components/display-3d-model) such in the example below:

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2F9hBWKKtzFu3kugZ07V89%2Fgrid-example-using-grid.png?alt=media&#x26;token=0f4b8437-55af-49e7-a160-afe894d06a5d" alt=""><figcaption><p>Guided work instructions using grid</p></figcaption></figure>

The `grid` for the above is set up as follows:

{% code title="main.view\.xml" %}

```xml
<grid column-count="6" column-min-width="100">
    <cell column-span="4">
        <!-- Add UI components here -->
    </cell>
    <cell column-span="2">
        <!-- Add UI components here -->
    </cell>
</grid>
```

{% endcode %}

### Controlled view layout

Another common use case for `grid` is to utilize more of the available screen space, by dividing the view into a number of cells and carefully positioning each UI component. For example:

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2FY7eyB9YPIGej1Pn7fRpW%2Fgrid-example-custom-view-layout.png?alt=media&#x26;token=4a6a08f3-c92b-4fee-9ac6-b2c210f175c5" alt=""><figcaption></figcaption></figure>

In this example the view is divided into 6 cells:

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2F5HcoUVmDdxRkDTyY5eWY%2Fgrid-example-custom-view-layout-annotated.png?alt=media&#x26;token=9ea0752b-8398-4463-8cd7-e68d8eaf491b" alt=""><figcaption></figcaption></figure>

The code for this `grid` is as follows:

```xml
<grid column-count="6" column-min-width="100">
    <cell column-span="1">
        <!-- Cell 1 -->
    </cell>
    <cell column-span="3">
        <!-- Cell 2 -->  
    </cell>
    <cell column-span="2">
        <!-- Cell 3 -->       
    </cell>
    <cell column-span="6">
        <!-- Cell 4 -->    
    </cell>
    <cell column-span="2">
        <!-- Cell 5 -->      
    </cell>
    <cell column-span="4">
        <!-- Cell 6 -->     
    </cell>
</grid>
```

### Responsive layout

`grid` is fully responsive to different screen sizes and orientations by default. This is illustrated by the simple example below:

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2FuADQtX3DwvDHXzcFFdnP%2FScreen%20Shot%202022-10-10%20at%204.58.40%20PM.png?alt=media&#x26;token=bcca944e-ae9a-4ec1-a280-6408537d8cee" alt=""><figcaption><p><strong>1024 px screen width</strong></p></figcaption></figure>

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2FjXkCaRCJUsdggS7sCeil%2FScreen%20Shot%202022-10-10%20at%204.59.24%20PM.png?alt=media&#x26;token=e220f374-423b-48c8-8fcf-cbede6c98de6" alt=""><figcaption><p><strong>768 px screen width</strong></p></figcaption></figure>

And the corresponding code:

{% code title="main.view\.xml" %}

```xml
<info>Select the condition of the asset:</info>
<grid>
    <cell>
        <button color="#ff0000" text-color="#fff" label="Extremely Poor" />
    </cell>
    <cell>
        <button color="#fd4900" text-color="#fff" label="Very Poor" />
    </cell>
    <cell>
        <button color="#f66d00" text-color="#fff" label="Poor" />
    </cell>
    <cell>
        <button color="#e98b00" text-color="#fff" label="Slightly Below Average" />
    </cell>
    <cell>
        <button color="#d7a700" label="Average"/>
    </cell>
    <cell>
        <button color="#bfbf00" label="Slightly Above Average" />
    </cell>
    <cell>
        <button color="#a0d600" label="Good" />
    </cell>
    <cell>
        <button color="#76eb00" label="Very Good" />
    </cell>
    <cell>
        <button color="#00ff00" label="Excellent" />
    </cell>
</grid>
```

{% endcode %}

When implementing the above use case with [`columns`](https://docs.journeyapps.com/reference/build/ui-components/all-ui-components/columns), notice how buttons hide behind a scrollbar beyond a certain width, and on smaller screens only one column is supported:

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2FaszZ00YxAFX7BArpQfux%2FScreen%20Shot%202022-10-10%20at%204.58.25%20PM.png?alt=media&#x26;token=a8f06b92-531f-49ba-b77a-01a2de1e3c23" alt=""><figcaption><p><strong>1024 px screen width</strong></p></figcaption></figure>

<figure><img src="https://2865107717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9TCHLR67eLHBOjPvHhud%2Fuploads%2FMhbIIyrQNRZWqNAezVcC%2FScreen%20Shot%202022-10-10%20at%204.59.44%20PM.png?alt=media&#x26;token=7a5ff399-1a7b-44c4-a501-0e77e7a7ac9d" alt=""><figcaption><p><strong>768 px screen width</strong></p></figcaption></figure>
