Can i create filter in subpanel view?
Short answer: Yes. If you need it to be dynamic that can be quite difficult, if you simply want an extra subpanel with a filter applied to it that is quite easy.
I started here
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
This is a really elegant solution thanks, I will give it a try on our development servers.
Thanks.
Instead of the file custom/Extension/modules/ModuleName/Ext/Layoutdefs//SubpanelDefinition.php
I had to add to the file custom/modules/ModuleName/Ext/Layoutdefs/layoutdefs.ext.php
@tien you shouldn’t modify that file, as it is automatically generated. You should be placing any changes in custom/Extension/modules
Thanks,
Will.
SuiteCRM 7.9.4
This solution is great but actually when you click on SEARCH it doesn’t filter the subpanel records…
ACTUALLY even the History Filter does NOT filter the records …
So upsetting.
This is a bug: https://github.com/salesagility/SuiteCRM/issues/2559
But no solution to make history and other subpanels filter work…
I had to add filter in opportunity subpanel in my application. I found a quick fix while testing
I am not using filter in other modules and do not know whether it will give permanent fix… Hope it will help
in include\SubPanel\SubPanel.js file
function showSearchPanel(subpanel){
// quickfic for opportunity subfilter in accounts - added these lines (place at appropriate place in the function)
var tempStr = subpanel.split('_');
if (tempStr[1] == 'opportunities') {
subpanel = tempStr[1];
}
function clearSearch(subpanel) {
// added to make clear button working (place at appropriate place in the function)
var url = ‘index.php?sugar_body_only=1&module=’+module+’&subpanel=’+subpanel+’&action=SubPanelViewer&inline=1&record=’+id + ‘&layout_def_key=’+module;
showSubPanel(subpanel,url,true);
in include\SubPanel\SubPanel.php file
function ProcessSubPanelListView($xTemplatePath, &$mod_strings)
{
// quickfix for subpanel filter (place at appropriate place in the function)
if ($this->search_query) {
if (!isset($this->subpanel_defs->panel_definition['where']) || $this->subpanel_defs->panel_definition['where'] == '') {
$this->subpanel_defs->panel_definition['where'] = $this->search_query;
} else {
$this->subpanel_defs->panel_definition['where'] .= ' AND ' . $this->search_query;
}
}
Hello,
is this solution still valid?
Thanks
Quentin