Search results

Load tab with DataSource

You can bind any data object to Tab items, by mapping it to a 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 Tab.

Source
Preview
index.js
index.html
ej.base.enableRipple(true);

var itemsData = [];
var mapping =  { header: 'FirstName', content: 'Notes' };

const SERVICE_URI = 'https://js.syncfusion.com/ejServices/Wcf/Northwind.svc/Employees';

new ej.data.DataManager({ url: SERVICE_URI, adaptor: new ej.data.ODataAdaptor})
    .executeQuery(new ej.data.Query().range(1, 4)).then((e) => {
        var result = e.result;

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

        //Initialize Tab component
        var tabObj = new ej.navigations.Tab({
            items: itemsData
        });

        //Render initialized Tab component
        tabObj.appendTo('#element');
    });
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Tab</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Essential JS 2 Tab">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

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


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