Creating a SubPanel Filter

sugarcrmdevelopers —  December 6, 2012 — 25 Comments

Editor’s Note: This post comes from Sugar Community Member Francesca Shiekh, who works for Sugar Professional Customer Wolfram Research. In this post, she shows how he solved the issue of building a subpanel filter.

We had a need to search within a subpanel without ever leaving the detail view we were on. In other words we wished to have a Subpanel Filter.

To achieve this I created a custom Widget that can be added to any standard subpanel and, by default, searches in the Name field of the corresponding table. Additionally I programmed in some exceptions to allow searching for the string in multiple fields for specific custom subpanels.

The result is a fill-in search form at the top of the subpanel:

When a search term is entered and the Filter is chosen the subpanel displays only matching records:

The “Clear” button will remove the filter and it will show all of the associated records.

Limitations:

  • The Activities subpanel is not a standard subpanel, it is a combination of multiple modules, therefore the filter will need modifications to work there.
  • The filter will break if Fancy Menus are chosen.

I would appreciate any suggestions for improvement: francescas@wolfram.com

The steps to achieve this were as follows:

  1. Define a custom Widget
  2. Define the search entry point
  3. Add the filter “button” to the desired subpanel

The code:

First, define the custom Widget. In custom/include/generic/SugarWidgets define SugarWidgetSubPanelTopFilterInputButton.php

Second, define the search entry point. Notice some special treatment for some custom tables where we wanted to search in more than just the name field in custom/entry_points define filter_subpanel.php

And finally, add the filter “button” to the desired subpanel. For example, to add to the Opportunities Subpanel on the Account add file addTopFilter.php to the custom/Extension/modules/Accounts/Ext/Layoutdefs.

25 responses to Creating a SubPanel Filter

  1. 

    Very nice indeed!

  2. 

    This is really cool, thank you for sharing 🙂

  3. 

    Any way to get this in the core product? This is huge as some people store hundreds of contacts, notes, etc related to an account. Great work!

  4. 

    The code for the widget is missing from the post. Here it is:

    get_name();

    $module_name = ($_REQUEST[‘module’]?$_REQUEST[‘module’]:”);

    $id = ($_REQUEST[‘record’]?$_REQUEST[‘record’]:”);

    $prior_search_params[$subpanel_name] = trim($_REQUEST[‘search_params’]?$_REQUEST[‘search_params’]:”);

    $onclick = “current_child_field = ‘{$subpanel_name}’;

    url=’index.php?sugar_body_only=1&module={$module_name}&subpanel={$subpanel_name}&entryPoint=filter_subpanel&inline=1&record={$id}&layout_def_key={$module_name}&search_params=’ + escape(document.getElementById(‘filter_param_’ + current_child_field).value) ;

    showSubPanel(‘{$subpanel_name}’,url,true,'{$module_name}’);

    document.getElementById(‘show_link_{$subpanel_name}’).style.display=’none’;

    document.getElementById(‘hide_link_{$subpanel_name}’).style.display=”;

    return false;”;

    $button = ”;

    $button .= “”;

    $button .= “”;

    $button .= “”;

    $button .= “”;

    return $button;

    }

    }

    ?>

    • 

      Let me try again – the code is not posting properly…
      This is the content of custom/include/generic/SugarWidgets/SugarWidgetSubPanelTopFilterInputButton.php

      if(!defined(‘sugarEntry’) || !sugarEntry) die(‘Not A Valid Entry Point’);

      require_once(‘include/generic/SugarWidgets/SugarWidgetSubPanelTopButton.php’);

      class SugarWidgetSubPanelTopFilterInputButton extends SugarWidgetSubPanelTopButton

      {

      function display(&$widget_data){

      $subpanel_definition = $widget_data[‘subpanel_definition’];

      $subpanel_name = $subpanel_definition->get_name();

      $module_name = ($_REQUEST[‘module’]?$_REQUEST[‘module’]:”);

      $id = ($_REQUEST[‘record’]?$_REQUEST[‘record’]:”);

      $prior_search_params[$subpanel_name] = trim($_REQUEST[‘search_params’]?$_REQUEST[‘search_params’]:”);

      $onclick = “current_child_field = ‘{$subpanel_name}’;

      url=’index.php?sugar_body_only=1&module={$module_name}&subpanel={$subpanel_name}&entryPoint=filter_subpanel&inline=1&record={$id}&layout_def_key={$module_name}&search_params=’ + escape(document.getElementById(‘filter_param_’ + current_child_field).value) ;

      showSubPanel(‘{$subpanel_name}’,url,true,'{$module_name}’);

      document.getElementById(‘show_link_{$subpanel_name}’).style.display=’none’;

      document.getElementById(‘hide_link_{$subpanel_name}’).style.display=”;

      return false;”;

      $button = ”;

      $button .= “”;

      $button .= “”;

      $button .= “”;

      $button .= “”;

      return $button;

      }

      }

  5. 

    Great work. Been waiting for something like this. +1 for creating a PR.

  6. 

    Thanks for your sharing,but it cannot work correctly in sugarcrmv6.5.2.Because the theme of sugarcrmv6.5.2 is diffrent,the subpanel’s top-button is drop-down box.I don’t know how to fix it.

    • 

      As stated in the “Limitations” the filter will break if you use fancy menus.
      You can go to System Settings and turn off fancy menus.
      I’ll be glad to see if someone can make it work with fancy menus.

    • 

      As stated in the “Limitations” the filter will break if you use fancy menus.
      You can go to System Settings and turn off fancy menus.
      I’ll be glad to see if someone can make it work with fancy menus.

    • 

      As stated in the “Limitations” the filter will break if you use fancy menus.
      You can go to System Settings and turn off fancy menus.
      I’ll be glad to see if someone can make it work with fancy menus.

  7. 

    Hi Francesca, can’t seem to get this to work on Corp 6.5.4. I’m assuming it’s the SugarWidgetTopFilterInputButton.php file that is incorrect, or it don’t like my version…

    The form appears on the sub-panel, custom module in Companies I’ve tried the original one posted above, no joy It reloads the entire page and no filter is applied. I have tried downloading the code from GitHub and using your adjusted code AND the code added by guest. Those two files give me a pop up window with an unexpected T_STRING error on line X, the second $button .= line

    $button .= “”;

    Is there a missing instruction? add the entrypoint to include/MVC/Controller/entry_point_registry.php

    Any thoughts gratefully accepted..

    • 

      in the line you quoted you have double quotes inside double quotes which will give a syntax error.

      instead of:

      $button .= “”;

      try:

      $button .= “”;

      or

      $button .= “”;

  8. 
    Météo Franck June 18, 2013 at 7:43 pm

    Hi, I’d like to know where I have to save the file from the 2nd stage (Second, define the search entry point. Notice some special treatment for some custom tables where we wanted to search in more than just the name field in custom/entry_points define filter_subpanel.php) ?
    Thanks

  9. 

    /custom/entry_points/filter_subpanel.php is the full path to the entry point

    custom/include/MVC/Controller/entry_point_registry.php is where you define the entry point.

    This is how I defined it:

    ###################################################################
    # Subpanel Filter
    ###################################################################

    $entry_point_registry[‘filter_subpanel’] =
    array(‘file’ => ‘custom/entry_points/filter_subpanel.php’, ‘auth’ => true);

  10. 

    For an extension that works on the History Subpanel see: http://developers.sugarcrm.com/wordpress/2013/07/05/a-history-subpanel-filter/

  11. 
    Gabriel Sandino Luna September 18, 2013 at 2:24 am

    Hi Francesca, Thanks for this article. I’m using the SugarCRM CE 6.4.2 version. I’m having some issues with this solution, maybe you could help me. For some reason when I click in the Filter button, it takes me to the index webpage. I’m not sure if for my Sugar version the URL’s are constructed in a different way…. Thanks for your help

  12. 

    can we search other fields in a form with currancies, dates, dropdown menus?

  13. 
    Darrel Hayner July 23, 2015 at 1:12 pm

    Is it possible to make the filter settings persist per user? So when switching to another Account detailview, the filtering would still be on & used?
    Thanks!

  14. 

    I need to have an in-line editing in sub panels in module as in detail views … any suggestions ?

Trackbacks and Pingbacks:

  1. subpanel filter (it works!)- critique needed - July 1, 2013

    […] […]

  2. SugarCRM Developer Blog » Blog Archive » A History Subpanel Filter - July 5, 2013

    […] Editor’s Note: This blog post is authored by Francesca Shiekh and Niklas Lanwehr as a followup to an earlier blog on Subpanel Filters. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s