Sidebar with list view in EJ2 JavaScript Sidebar control

2 May 20235 minutes to read

Any HTML element can be placed in the Sidebar content area. Sidebar supports all types of HTML structures like TreeView, ListView, etc.

In the following example, the Sidebar is rendered with ListView component in its content area.


// Initialize ListView component
var data = [
    { text: 'Home', id: 'list-02' },
    { text: 'Offers', id: 'list-03' },
    { text: 'Support', id: 'list-04' },
    { text: 'Logout', id: 'list-06' }

var listInstance = new ej.lists.ListView({
    //Set defined data to dataSource property
    dataSource: data

// Initialize Sidebar component
var defaultSidebar= new ej.navigations.Sidebar({
    type: "Over", 
    width: '100%'

//Click to toggle the Sidebar
document.getElementById('toggle').onclick = function() {

// Close the sidebar
document.getElementById('close').onclick = function() {
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Sidebar</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="styles.css" rel="stylesheet">
<script src="" type="text/javascript"></script>
<script src="" type ="text/javascript"></script>

    <div id="container">
        <!-- sidebar element declaration -->
        <aside id="default-sidebar">
            <div class="title1">Menu</div>
            <div class="closebtn">
                <button id="close" class="e-btn close-btn">
                    <span id="innerclose" class="e-icons close-icon"></span>
            <div id="listcontainer">
                <div id="list"></div>
            <div class="sub-title">
                * ListView component is placed inside the sidebar content area.
        <!-- end of sidebar element -->
        <!-- main content declaration -->
            <div class="title2">Main content</div>
            <div class="sub-title"> Click the button to open/close the Sidebar.</div>
            <div style="padding:20px" class="center-align">
                <button id="toggle" class="e-btn e-info">Toggle Sidebar</button>

var ele = document.getElementById('container');
if(ele) { = "visible";
<script src="index.js" type="text/javascript"></script>