{"id":2728,"date":"2015-03-09T17:33:12","date_gmt":"2015-03-09T13:33:12","guid":{"rendered":"http:\/\/www.dhtmlx.com\/blog\/?p=2728"},"modified":"2026-04-03T15:35:55","modified_gmt":"2026-04-03T12:35:55","slug":"loading-content-into-tabs-on-demand","status":"publish","type":"post","link":"https:\/\/dhtmlx.com\/blog\/loading-content-into-tabs-on-demand\/","title":{"rendered":"DHTMLX Little-Known Features: Loading Content into Tabs on Demand"},"content":{"rendered":"<p>\n        <div class=\"info-block\">\n            <div class=\"info-icon\">\n                <svg viewBox=\"0 0 14 16\">\n                    <path fill-rule=\"evenodd\" d=\"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z\"><\/path>\n                <\/svg>\n\n                INFO\n            <\/div>\n\n            <div class=\"info-content\">\n                <p>\n                    If you are using an outdated version of DHTMLX Suite 5 and require the documentation for it, \n                    please <a href=\"https:\/\/dhtmlx.com\/docs\/contact.shtml\" title=\"\">contact us<\/a>, <br \/>and we will send it to you.\n                <\/p>\n            <\/div>\n        <\/div>\n    <br \/>\nWe continue sharing small tricks and tips that enable so many abilities when using our <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxSuite\/\" target=\"_blank\">JavaScript widget library<\/a> &#8211; DHTMLX Suite. This time we&#8217;ll show you how to load content into tabs on demand.<\/p>\n<p>The described ability allows you to decrease the load on your app. The end-users of your product may not need all the content to be load at once. Nobody will deny that this feature will make your app faster and more efficient.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2015\/03\/load-content-into-tabs-4.png\" alt=\"load-content-into-tabs-on-demand\" width=\"433\" height=\"330\" class=\"aligncenter size-full wp-image-2729\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2015\/03\/load-content-into-tabs-4.png 433w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2015\/03\/load-content-into-tabs-4-300x228.png 300w\" sizes=\"auto, (max-width: 433px) 100vw, 433px\" \/><br \/>\n<!--more--><br \/>\nAnd now let&#8217;s see what we need to do for it. <\/p>\n<p><strong>Step 1.<\/strong> First of all, we init the tabbar:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">myTabbar <span class=\"sy0\">=<\/span> <span class=\"kw1\">new<\/span> dhtmlXTabBar<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; parent<span class=\"sy0\">:<\/span> <span class=\"st0\">&quot;tabbarObj&quot;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; tabs<span class=\"sy0\">:<\/span> <span class=\"br0\">&#91;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span>id<span class=\"sy0\">:<\/span> <span class=\"st0\">&quot;a1&quot;<\/span><span class=\"sy0\">,<\/span> text<span class=\"sy0\">:<\/span> <span class=\"st0\">&quot;Tab 1&quot;<\/span><span class=\"br0\">&#125;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span>id<span class=\"sy0\">:<\/span> <span class=\"st0\">&quot;a2&quot;<\/span><span class=\"sy0\">,<\/span> text<span class=\"sy0\">:<\/span> <span class=\"st0\">&quot;Tab 2&quot;<\/span><span class=\"br0\">&#125;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span>id<span class=\"sy0\">:<\/span> <span class=\"st0\">&quot;a3&quot;<\/span><span class=\"sy0\">,<\/span> text<span class=\"sy0\">:<\/span> <span class=\"st0\">&quot;Tab 3&quot;<\/span><span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#93;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>Notice that we don&#8217;t select any tab yet, because we need to add onSelect even handler at first to call it at the tab selection.<\/p>\n<p><strong>Step 2.<\/strong> Then we attach onSelect event handler to the tabbar:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">myTabbar.<span class=\"me1\">attachEvent<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;onSelect&quot;<\/span><span class=\"sy0\">,<\/span> doOnSelect<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>And also we need the event handler itself:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\"><span class=\"kw1\">function<\/span> doOnSelect<span class=\"br0\">&#40;<\/span>id<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ check if tab is not inited yet<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span>initedTabs<span class=\"br0\">&#91;<\/span>id<span class=\"br0\">&#93;<\/span> <span class=\"sy0\">!=<\/span> <span class=\"kw2\">true<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ init component<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">var<\/span> myComponent <span class=\"sy0\">=<\/span> myTabbar.<span class=\"me1\">cells<\/span><span class=\"br0\">&#40;<\/span>id<span class=\"br0\">&#41;<\/span>.<span class=\"me1\">attachComponent<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; myComponent.<span class=\"me1\">doSome<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; ...<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ mark tab as inited<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; initedTabs<span class=\"br0\">&#91;<\/span>id<span class=\"br0\">&#93;<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw2\">true<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ return 'true' to allow tab to be selected<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"kw2\">true<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>In this case we create initedTabs variable and save the data in it about whether the tab is selected 1 time at least:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\"><span class=\"kw1\">var<\/span> initedTabs <span class=\"sy0\">=<\/span> <span class=\"br0\">&#123;<\/span><span class=\"br0\">&#125;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p><strong>Step 3.<\/strong> The next and final step is to select the first tab (i.e. selected tab on init), and then force onSelect event trigger (set the 1st param to &#8216;true&#8217;):<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">myTabbar.<span class=\"me1\">cells<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;a1&quot;<\/span><span class=\"br0\">&#41;<\/span>.<span class=\"me1\">setActive<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw2\">true<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>When you try to apply our tips, feel free to leave your comments about the received result in the comments section below. We&#8217;ll be happy to know that <a href=\"https:\/\/dhtmlx.com\/blog\/tag\/dhtmlx-tips\/\" target=\"_blank\">our articles<\/a> come useful for you. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>We continue sharing small tricks and tips that enable so many abilities when using our JavaScript widget library &#8211; DHTMLX Suite. This time we&#8217;ll show you how to load &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3307,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,72,1],"tags":[33,43,14,10],"class_list":["post-2728","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-posts-for-codeproject-com","category-general","category-uncategorized","tag-all-posts","tag-dhtmlx-tips","tag-tips","tag-dhtmlxsuite"],"_links":{"self":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/2728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/comments?post=2728"}],"version-history":[{"count":2,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/2728\/revisions"}],"predecessor-version":[{"id":15362,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/2728\/revisions\/15362"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media\/3307"}],"wp:attachment":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media?parent=2728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/categories?post=2728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/tags?post=2728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}