Search results

Expand and Collapse in JavaScript Splitter control

Collapsible panes

The Splitter panes can be configured with built-in expand and collapse functionalities. By default, the collapsible behavior is disabled. Enable the collapsible behavior in the paneSettings property to show or hide the expand or collapse icons in the panes. You can dynamically expand and collapse the panes by the corresponding icons.

The following code shows how to enable collapsible behavior.

Source
Preview
app.ts
index.html
index.css
import { Splitter } from '@syncfusion/ej2-layouts';

let splitObj: Splitter = new Splitter({
    height: '250px',
    paneSettings: [
        { collapsible: true },
        { collapsible: true },
        { collapsible: true }
    ],
    separatorSize: 2,
    width: '100%'
});
splitObj.appendTo('#splitter');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 Splitter Expand/Collapse </title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 Uploader Component" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>
<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <!--element which is going to render the splitter-->
<div class="default">
        <div id="splitter" >
            <div>
                <div class="content">
                    <h3 class="h3">PARIS </h3>
                    Paris, the city of lights and love - this short guide is full of ideas for how to make the most of the romanticism...
                </div>
            </div>
            <div>
                <div class="content">
                    <h3 class="h3">CAMEMBERT </h3>
                    The village in the Orne department of Normandy where the famous French cheese is originated from.
                </div>
            </div>
            <div>
                <div class="content">
                    <h3 class="h3">GRENOBLE </h3>
                    The capital city of the French Alps and a major scientific center surrounded by many ski resorts, host of the Winter Olympics in 1968.
                </div>
            </div>
        </div>
    </div>

    </div>
</body>
</html>
#container {  
  margin: 60px auto;
  width: 500px;
}

#loader {
  color: #008cff;
  font-family: 'Helvetica Neue','calibiri';
  font-size: 14px;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;
}

.h3 {
	font-size: 14px;
}

.content {
	padding: 9px;
}
.default {
	margin: 50px auto;
	max-width: 700px;
}

Programmatically control the expand and collapse action

The Splitter provides public method to control the expand and collapse behavior programmatically using the expand and collapse methods. Refer to the following code example.

Source
Preview
app.ts
index.html
index.css
import { Splitter } from '@syncfusion/ej2-layouts';

let splitObj: Splitter = new Splitter({
    height: '230px',
    paneSettings: [
        { collapsible: true },
        { collapsible: true },
        { collapsible: true }
    ],
    width: '100%'
});
splitObj.appendTo('#splitter');

document.getElementById('expand').onclick = (): void => {
   splitObj.expand(0);
}
document.getElementById('collapse').onclick = (): void => {
   splitObj.collapse(0);
}
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 Splitter </title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 Uploader Component" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>
<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <!--element which is going to render the splitter-->
<div class="default">
        <div id="splitter" >
            <div>
                <div class="content">
                    <h3 class="h3">PARIS </h3>
                    Paris, the city of lights and love - this short guide is full of ideas for how to make the most of the romanticism...
                </div>
            </div>
            <div>
                <div class="content">
                    <h3 class="h3">CAMEMBERT </h3>
                    The village in the Orne department of Normandy where the famous French cheese is originated from.
                </div>
            </div>
            <div>
                <div class="content">
                    <h3 class="h3">GRENOBLE </h3>
                    The capital city of the French Alps and a major scientific center surrounded by many ski resorts, host of the Winter Olympics in 1968.
                </div>
            </div>
        </div>
    </div>
	<button id ="expand" class="e-control e-btn e-lib">expand</button>
	<button id ="collapse" class="e-control e-btn e-lib">collapse</button>

    </div>
</body>
</html>
#container {
  margin: 0px auto;
  width: 600px;
}

#loader {
  color: #008cff;
  font-family: 'Helvetica Neue','calibiri';
  font-size: 14px;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;
}

.h3 {
	font-size: 14px;
}

.content {
	padding: 9px;
}
.default {
	margin: 50px auto;
	max-width: 700px;
}

Specify initial state to panes

You can render specific panes with collapsed state on page load. Specify a Boolean value to the collapsed property to control this behavior. The following code explains how to collapse panes on rendering (the second panes renders with collapsed state).

Source
Preview
app.ts
index.html
index.css
import { Splitter } from '@syncfusion/ej2-layouts';

let splitObj: Splitter = new Splitter({
    height: '250px',
    paneSettings: [
        { collapsible: true },
        { collapsible: true, collapsed: true },
        { collapsible: true }
    ],
    width: '100%'
});
splitObj.appendTo('#splitter');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 Splitter </title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 Uploader Component" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>
<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <!--element which is going to render the splitter-->
<div class="default">
        <div id="splitter" >
            <div>
                <div class="content">
                    <h3 class="h3">PARIS </h3>
                    Paris, the city of lights and love - this short guide is full of ideas for how to make the most of the romanticism...
                </div>
            </div>
            <div>
                <div class="content">
                    <h3 class="h3">CAMEMBERT </h3>
                    The village in the Orne department of Normandy where the famous French cheese is originated from.
                </div>
            </div>
            <div>
                <div class="content">
                    <h3 class="h3">GRENOBLE </h3>
                    The capital city of the French Alps and a major scientific center surrounded by many ski resorts, host of the Winter Olympics in 1968.
                </div>
            </div>
        </div>
    </div>

    </div>
</body>
</html>
#container {
  margin: 60px auto;
  width: 600px;
}

#loader {
  color: #008cff;
  font-family: 'Helvetica Neue','calibiri';
  font-size: 14px;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;
}

.h3 {
	font-size: 14px;
}

.content {
	padding: 9px;
}
.default {
	margin: 50px auto;
	max-width: 700px;
}

See Also