Search results

Load accordion with DataSource in JavaScript (ES5) Accordion control

06 Jun 2023 / 1 minute to read

You can bind any data object to Accordion items, by mapping it to header and content  property.

In the below demo, Data is fetched from an OData service using DataManager. The result data is formatted as a JSON object with header and content fields, which is set to items property of Accordion.

Copied to clipboard
var itemsData = [];
var mapping =  { header: 'FirstName', content: 'Notes' };
const SERVICE_URI = '';

new{ url: SERVICE_URI, adaptor: new})
    .executeQuery(new, 4)).then(function (e) {

    var result = e.result;

    for(var i = 0; i < result.length; i++) {
        itemsData.push({ header: result[i][mapping.header], content: result[i][mapping.content] });

    //Initialize Accordion component
    var accordion = new ej.navigations.Accordion({
        items: itemsData

    //Render initialized Accordion component
Copied to clipboard
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Accordion</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Toolbar Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="//" rel="stylesheet">
<script src="" type="text/javascript"></script>

    <div id="container">
        <div id="element"></div>
        <div id="result"></div>

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