Expand and collapse in EJ2 TypeScript Splitter control
3 Feb 202414 minutes to read
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.
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="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></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>
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.
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="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></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>
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).
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="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></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>