# Split Pane

## Overview

The Split Pane component is a container that shows a 'left' (1) and a 'right' (2) form in it. It will show both forms at the same time, placed either horizontally or vertically, with a divider between them. These 2 forms can optionally show related data.

The divider's location can be modified either from code or directly by the user.\
It is suited for use in both Advanced (Responsive) and Simple CSS forms.

## Get Started

<div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-5ac8939869665e5750cb550cf0a8f966ed7695f0%2Fsplitpane_demo.gif?alt=media" alt=""><figcaption><p>Split Pane</p></figcaption></figure></div>

### Creating a Split Pane

<div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-e98da397fa8ffa5eb3c4f63e12c563fec61fc3ac%2Fsplitpane_create.gif?alt=media" alt=""><figcaption><p>Create a Split Pane</p></figcaption></figure></div>

Here are the steps for creating a Split Pane:

1. Open the [Form Editor](https://docs.servoy.com/reference/servoy-developer/object-editors/form-editor) of the form where you need to place a **Split Pane**
2. Find **Split Pane** in *Form Containers* section in the components' pallet
3. Drag and drop the **Split Pane** component in the desired place of the form
4. Set the panels' orientation by selecting [`splitType`](https://docs.servoy.com/reference/servoyextensions/ui-components/form-containers/split-pane#splittype) property

   <div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-4bfd3e7cfb9fde61544d1f7b581c6e9de39374c2%2FsplitType.jpg?alt=media&#x26;token=15097ad8-d6ff-4514-8036-0e9982670698" alt=""><figcaption></figcaption></figure></div>
5. Add `pane1` and `pane2`

   <div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-327ad209047fc305eb0f7dc48ee00f473f055183%2Fsplitpane-add-pane.jpg?alt=media&#x26;token=255820ec-fdd7-4699-88aa-13b365fcf7a7" alt=""><figcaption></figcaption></figure></div>
6. Add forms in [`containedForm`](https://docs.servoy.com/reference/servoyextensions/ui-components/form-containers/split-pane#containsformid) panels' property, where you set the name of the form you want to be displayed in each panel

   <div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-a9da5f620bd521351894d7ce2069387c23e8de74%2Fsplitpane-add-contained-form.jpg?alt=media&#x26;token=dc769d4b-7580-4119-9cff-d0571a1fcf99" alt=""><figcaption></figcaption></figure></div>
7. Optionally, you can [use a relation](#using-a-relation) by selecting the [`relationName`](https://docs.servoy.com/reference/servoyextensions/ui-components/form-containers/split-pane#relationname) property, where you set the [relation](https://docs.servoy.com/guides/develop/application-design/data-modeling/relations) between the main form and the contained form of the panel

   <div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-030727cba9c55d1be4918485308e5f30fd8b1be0%2Fsplitpane-add-relation.jpg?alt=media" alt=""><figcaption></figcaption></figure></div>
8. Set `pane1MinSize` (minimum size of first panel in pixels) and `pane2MinSize` (minimum size of second panel in pixels)

   <div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-8136f995181f7864e12ee1b437f063753f033194%2Fsplitpane-pane-minsize.jpg?alt=media&#x26;token=bbfe66af-aa24-4593-b2cb-2301796b82a9" alt=""><figcaption></figcaption></figure></div>
9. Set the [divider properties](#setting-the-divider-properties)
10. Edit other [**Split Pane** properties](https://docs.servoy.com/reference/servoyextensions/ui-components/form-containers/split-pane#properties) if needed

{% hint style="info" %}
It is recommended to set a specific `name` in the **Split Pane** properties in order to make it easier to use it later in scripting.\
Example: `"splitpane_orders"`.

<img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-99931de7d44740fb2d2a7fd97e60325ecdd4ca9e%2Fsplit-pane-name.jpg?alt=media&#x26;token=660c4346-bac7-4b70-8030-6a060d3bf1fe" alt="Split Pane name" data-size="original">
{% endhint %}

### Using a relation

The contained form of the panels can show related data. In order to do this, you need to have the following:

1. Set the [`datasource`](https://docs.servoy.com/reference/servoycore/object-model/solution/form#datasource) property on the main form
2. Set the [`datasource`](https://docs.servoy.com/reference/servoycore/object-model/solution/form#datasource) property on the contained form
3. Make sure that the [relation](https://docs.servoy.com/guides/develop/application-design/data-modeling/relations) from datasource table of the main form to datasource table of the contained form exists, otherwise it needs to be created
4. Set the above relation in the [`relationName`](https://docs.servoy.com/reference/servoyextensions/ui-components/form-containers/split-pane#relationname) property of the corresponding panel

Once everything is set, the contained form will show related data according to the selected record in the main form. When the selected record changes in the main form, so will the related data from the contained form.

### Setting the divider properties

<figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-bcb8b82256d5673b633444436c233010fb43569e%2Fsplitpane-divider-prop.jpg?alt=media&#x26;token=96381698-f4dc-47b5-93ee-247c363dd6ca" alt=""><figcaption><p>divider properties</p></figcaption></figure>

**Divider location** is set by using the [divLocation](https://docs.servoy.com/reference/servoyextensions/ui-components/form-containers/split-pane#divlocation) property: sets the initial splitter div location, between 0 and 1 is a percentage, more than 1 is a value in pixels. If location is less than 1 (-1 or .5 = middle, lower then .5 = close to left/top, higher then .5 = close to right/bottom), then the location will be considered at (location \* 100) percent of the split pane from left, otherwise it will represent the pixels from left.

**Width of divider** is set by using the [divSize](https://docs.servoy.com/reference/servoyextensions/ui-components/form-containers/split-pane#divsize) property, which represents the divider size in pixels.

## Scripting a Split Pane

[**Split Pane** properties](https://docs.servoy.com/reference/servoyextensions/ui-components/form-containers/split-pane#properties) can be also set in the [Scripting Editor](https://docs.servoy.com/reference/servoy-developer/object-editors/scripting-editor).\
You can find a list of Split Pane API methods [here](https://docs.servoy.com/reference/servoyextensions/ui-components/form-containers/split-pane#api).

### Setting the forms

Here is an example of how to programmatically set the contained form, including relationName, in the [Scripting Editor](https://docs.servoy.com/reference/servoy-developer/object-editors/scripting-editor) of the main form:

```javascript
/**
 * Callback method when form is (re)loaded.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @private
 *
 * @properties={typeid:24,uuid:"2A6697C8-38B1-4264-9D8B-2C3B5758FFC6"}
 */
function onLoad(event) {
    // TODO Auto-generated method stub
    // splitpane_orders = the name of the Split Pane container in the main form
    // pane1 = panel on the left / top 
    // pane2 = panel on the right / bottom
    // order_details = the contained form in pane1
    // orders_to_order_details = relation between datasource table of the main form to datasource table of the pane1 contained form
    // orders_customers = the contained form in pane2
    // orders_to_customers = relation between datasource table of the main form to datasource table of the pane2 contained form
    elements.splitpane_orders.pane1.containsFormId = forms.order_details;
    elements.splitpane_orders.pane1.relationName = orders_to_order_details;
    elements.splitpane_orders.pane2.containsFormId = forms.orders_customers;
    elements.splitpane_orders.pane2.relationName = orders_to_customers;
}
```

### Moving the divider

Here is an example of how to save the previous divider location in the [Scripting Editor](https://docs.servoy.com/reference/servoy-developer/object-editors/scripting-editor) of the main form and set the same for the next user session:

Saving the divider location in the `onChange` event(fired after divider location changed) of the Split Pane container:

```javascript
/**
 * @param {Number} previousIndex
 * @param {JSEvent} event
 *
 * @private
 *
 * @properties={typeid:24,uuid:"FC548162-34E1-4AD0-91C4-390222D478CA"}
 */
function onChange(previousIndex, event) {
    // TODO Auto-generated method stub
    application.setUserProperty(controller.getName()+"."+elements.splitpane_orders.getName()+".divider",elements.splitpane_orders.getDividerLocation().toString())
}
```

Checking if there is a saved previous divider location and set it in the `onLoad` main form event:

```javascript
/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"2FD6AD36-9779-49D2-B4A7-985C7C73B66C",variableType:8}
 */
var dividerLocation;

/**
 * Callback method when form is (re)loaded.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @private
 *
 * @properties={typeid:24,uuid:"2751B88B-48CF-477C-8422-0BC79FFDDED5"}
 */

function onLoad(event) {
    // TODO Auto-generated method stub
    dividerLocation = application.getUserProperty(controller.getName()+"."+elements.splitpane_orders.getName()+".divider");
    if (dividerLocation)
    {
        elements.splitpane_orders.divLocation = parseInt(dividerLocation);
    }   
}
```
