{"id":2977,"date":"2023-08-22T19:55:30","date_gmt":"2023-08-23T00:55:30","guid":{"rendered":"https:\/\/xlinesoft.com\/blog\/?p=2977"},"modified":"2024-04-13T11:59:54","modified_gmt":"2024-04-13T16:59:54","slug":"tabbed-elements-in-dashboards","status":"publish","type":"post","link":"https:\/\/xlinesoft.com\/blog\/2023\/08\/22\/tabbed-elements-in-dashboards\/","title":{"rendered":"Tabbed elements in dashboards"},"content":{"rendered":"<p>Dashboards excel at showcasing a multitude of valuable information on a single page. However, there are instances when a basic dashboard layout falls short in accommodating the desired volume of data on a single screen. In this article, we will demonstrate a method for amplifying information presentation through the use of a tabbed component. It&#8217;s important to note that this is not a built-in and we will need to write a bit of code. <\/p>\n<p>Here is what we after:<\/p>\n<p><a href=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr-600x435.png\" alt=\"\" width=\"600\" height=\"435\" class=\"alignnone size-medium wp-image-2983\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr-600x435.png 600w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr-1024x743.png 1024w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr-768x557.png 768w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr.png 1368w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><br \/>\n<!--more--><\/p>\n<h3>Instructions<\/h3>\n<p>1. Create a dashboard<\/p>\n<p>Dashboard layout needs to conform the following structure. The first row needs to have a single cell with the code snippet. All other objects that you want to appear in a tabbed element should occupy rows below the code snippet. It doesn&#8217;t matter how many elements are in each row, they will be moved inside the tabbed element anyway. In our example we are going to display three grids, a single record, a chart and a report inside the tabbed element. <\/p>\n<p>Here is a sample layout:<br \/>\n<a href=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr2-600x329.png\" alt=\"\" width=\"600\" height=\"329\" class=\"alignnone size-medium wp-image-2981\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr2-600x329.png 600w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr2-1024x561.png 1024w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr2-768x421.png 768w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr2-1536x842.png 1536w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2023\/08\/scr2.png 1782w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>2. Code snippet <\/p>\n<p>The idea of this code is to display an empty tabbed panel. Nothing special here, just a basic Bootstrap-based HTML code. The only important thing here is the ID of this panel which is <strong>dashTabs<\/strong>. We are going to use this ID in both Javascript and CSS code. <\/p>\n<p><strong>PHP<\/strong><\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"php\" name=\"mshighlighter\" >\r\n$header = \"Tabs\";\r\necho \"<div class='panel with-tabs panel-default form-tabs' id='dashTabs'>\r\n<div class='panel-heading'>\r\n<ul class='nav nav-tabs' role='tablist'>\r\n<\/ul>\r\n<\/div>\r\n<div class='panel-body'>\r\n<div class='tab-content'>\r\n<\/div>\r\n<\/div>\r\n<\/div>\";<\/textarea><\/pre>\n<\/div>\n<p><strong>C#<\/strong><\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"javascript\" name=\"mshighlighter\" >\r\nheader = new XVar(\"Tabs\");\r\nMVCFunctions.Echo(\"<div class='panel with-tabs panel-default form-tabs' id='dashTabs'>\\r\\n<div class='panel-heading'>\\r\\n<ul class='nav nav-tabs' role='tablist'>\\r\\n<\/ul>\\r\\n<\/div>\\r\\n<div class='panel-body'>\\r\\n<div class='tab-content'>\\r\\n<\/div>\\r\\n<\/div>\\r\\n<\/div>\");<\/textarea><\/pre>\n<\/div>\n<p>3. Dashboard Javascript OnLoad event<\/p>\n<p>This code loops through the array of dashboard elements and moves them one by one to the tabbed panel. See inline comments for more info. <\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"javascript\" name=\"mshighlighter\" >\r\n\/\/ an array with all the dashboard element that we want to display in individual tabs\r\nvar tabs_pages = [\r\n    { table: \"employees\", page: \"grid\" },\r\n    { table: \"customers\", page: \"grid\" },\r\n    { table: \"customers\", page: \"record\" },\r\n    { table: \"Bar Chart\", page: \"chart\" },\r\n    { table: \"order details\", page: \"grid\" },\r\n    { table: \"categories Report\", page: \"report\" }\r\n];\r\n\r\n$.each(tabs_pages, function () {\r\n    var goodTableName = Runner.goodFieldName(this.table);\r\n    var tabId = goodTableName + \"_\" + this.page;\r\n    \r\n\/\/ adding a new tab \r\n\r\n    $(\".nav\", \"#dashTabs\").append(\"<li role='presentation'><a aria-controls='settings' role='tab' data-toggle='tab' href='#\" + tabId + \"'>\" + this.table + \" \" + this.page + \"<\/a><\/li>\");\r\n    $(\".tab-content\", \"#dashTabs\").append(\"<div role='tabpanel' class='tab-pane' id='\" + tabId + \"'><\/div>\");\r\n\r\n    var pageDashElement = $(\"#dashelement_\"+goodTableName+\"_\"+this.page+pageid);\r\n\r\n\/\/ adding a CSS class for the new tab element \r\n    pageDashElement.addClass(\"tabelement\");\r\n\r\n\/\/ adding this new element to the tab \r\n    $(\"#\" + tabId).append(pageDashElement);\r\n});\r\n\r\n\/\/ make sure that the first tab is selected\r\n$(\"li[role='presentation']\", \"#dashTabs\").first().find(\"a\").click();<\/textarea><\/pre>\n<\/div>\n<p>4. Custom CSS<\/p>\n<p>This code goes to <strong>Style Editor -> Modify CSS<\/strong> section. Just hiding some unnecessary decoration and making tabs look prettier.  <\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"css\" name=\"mshighlighter\" >\r\n[data-itemtype=\"dashboard-item\"].tabelement .panel-heading{\r\n    background: none;\r\n    border: none;\r\n}\r\n[data-itemtype=\"dashboard-item\"].tabelement .panel-heading .rnr-dbebrick{\r\n    color:#337ab7;\r\n}\r\n[data-itemtype=\"dashboard-item\"].tabelement .panel-heading .rnr-dbebrick .btn{\r\n    background: #337AB7;\r\n    color: white;\r\n}<\/textarea><\/pre>\n<\/div>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dashboards excel at showcasing a multitude of valuable information on a single page. However, there are instances when a basic dashboard layout falls short in accommodating the desired volume of data on a single screen. In this article, we will demonstrate a method for amplifying information presentation through the use of a tabbed component. It&#8217;s important to note that this is not a built-in and we will need to write a bit of code. Here is what we after:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,1,8],"tags":[],"_links":{"self":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/2977"}],"collection":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/comments?post=2977"}],"version-history":[{"count":7,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/2977\/revisions"}],"predecessor-version":[{"id":3120,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/2977\/revisions\/3120"}],"wp:attachment":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/media?parent=2977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/categories?post=2977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/tags?post=2977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}