Hy! Actually there is an easier way than the one at Sugar developer blog
A while ago we had an similar requirement to enable filtering in subpanel like it has History subpanel. After initial searching I found out that Suite has almost complete and easy reusable out-of-the-box solution. However there are two pitfalls:
The first one is filter button definition in include/generic/SugarWidgets/SugarWidgetSubPanelTopFilterButton.php at line 18. At onclick definition the ‘history’ subpanel name is hardcoded string.
Problem: onclick=“showSearchPanel(’[color=#ff0000]history[/color]’);return false;”
Solution: Replacing history string with
".$defines['subpanel_definition']->name."
so the onclick snippet looks like this ->
onclick=\"showSearchPanel('".$defines['subpanel_definition']->name."');return false;\"
Secondly, in /custom/include/Subpanel/SubPanel.js at line 36 when initiating ajax call an Accounts module name is hardcoded in url string.
Problem: $.ajax({url:“index.php?module=[color=#ff0000]Accounts[/color]&action=SubPanelSearch&subpanel=”+subpanel,
Solution: Replacing Accounts string with [color=#00ff00]‘currentModule’[/color] variable so the url snippet becomes this ->
$.ajax({url:"index.php?module="+currentModule+"&action=SubPanelSearch&subpanel="+subpanel
After that we only need to add button and searchdefs in subpanel setup in the custom/Extension/modules/ModuleName/Ext/Layoutdefs/SubpanelDefinition.php:
$layout_defs["ModuleName"]["subpanel_setup"]['SubpanelName']['top_buttons'] =
array (
0 =>
array (
'widget_class' => 'SubPanelTopButtonQuickCreate',
),
1 =>
array (
'widget_class' => 'SubPanelTopSelectButton',
'mode' => 'MultiSelect',
),
2 =>
array (
'widget_class' => 'SubPanelTopFilterButton',
),
);
$layout_defs["ModuleName"]["subpanel_setup"]['SubpanelName']['searchdefs'] =
array ( 'name' =>
array (
'name' => 'name',
'default' => true,
'width' => '10%',
),
);
I hope this post will be helpfull to you and is pointing at what you need.
I would also like to freely suggest to SuiteCRM to include the solution of two ‘problems’ in some of next releases if it already isn’t on their mind, so we won’t have to worry about them in future and just write supanel definition.
Thanks,
bye