Remove subpanel from detailview if it doesn’t have records

Sometimes Scrolling DetailView is annoying if many subpanel has no records into it.

We come across interesting requirement in which we have to remove all those subpanel which has no records, so user are easily check the related records without much scrolling.

We achieve the functionality as follows.

For Example, We have to do changes for Accounts module.

Steps are as below,

1. Create / Edit custom/modules/Accounts/views/view.detail.php

Add the following code into it.

function _displaySubPanels(){
global $db;
require_once ('include/SubPanel/SubPanelTiles.php');
$subpanel = new SubPanelTiles($this->bean, $this->module);

$subpanelLists = $subpanel->subpanel_definitions->layout_defs['subpanel_setup'];
foreach($subpanelLists as $subpanelModuleName => $subpanelModuleDefinations)
{
     $notConsiderSubpanel = array('activities','history');
     if(!in_array($subpanelModuleName,$notConsiderSubpanel) && array_key_exists("get_subpanel_data", $subpanelModuleDefinations) && !empty($subpanelModuleDefinations['get_subpanel_data']))
     {
          $loadRelationshipName = $subpanelModuleDefinations['get_subpanel_data'];
          $pos = strpos($loadRelationshipName, "function:");
          if ($pos === false)
          {
               $this->bean->load_relationship($loadRelationshipName);
               if(empty($this->bean->$loadRelationshipName->getBeans()))
               {
                    unset($subpanel->subpanel_definitions->layout_defs['subpanel_setup'][$subpanelModuleName]);
               }
          }
     }
}

echo $subpanel->display();
}

2. Refresh the Account’s DetailView and see the effects.

Before Customization
After Customization

Hope you find this blog post helpful.

Feel free to add comments and queries, that helps us to improve the quality of posts.

You can contact us at info@infotechbuddies.com

Thank you.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *