Select elements for Group by dropdown

dimoss

Well-Known Member
Hi,

the "Group by" list feature has by default all the elements that are visible in the list.
Is it possible to select only specific elements to appear in the dropdown?
Thanks,
 
Last edited:
I don't think so.

You can create a "custom" group_by by modifying default_buttons.php in a custom template
You can skip elements you don't want to show in the GroupBy loop.
 
Hi @troester

I tried to tweak the group by part of the default_buttons.php changing as follows but the Group By button dissapeared.

PHP:
<?php if ($this->canGroupBy) : ?>
    <div class="col px-0">
        <?php
        $displayData = new stdClass;
        $displayData->icon = FabrikHelperHTML::icon('icon-list-view');
        $displayData->label = Text::_('COM_FABRIK_GROUP_BY');
        $displayData->links = array();

        $elementsToDisplay = array('vw_pm___EventName', 'vw_pm___Organization');

        foreach ($this->groupByHeadings as $url => $obj) :
            
            if (in_array($obj->element_name, $elementsToDisplay)) :
                $displayData->links[] = '<a class="nav-link" data-groupby="' . $obj->group_by . '" href="' . $url . '">' . $obj->label . '</a>';
            endif;
        endforeach;
        ?>
    </div>
<?php endif;

I defined an array $elementsToDisplay that contains the names of the specific elements to display. Inside the loop, i use in_array() function to check if the current element's name ($obj->element_name) is in the $elementsToDisplay array so that if it is, I add it to the $displayData->links array for display. However nothing in the output.
Any help?
 
It seems you deleted

$layout = $this->getModel()->getLayout('fabrik-nav-dropdown');
echo $layout->render($displayData);
after the loop.
 
Debug $this->groupByHeadings to get the 'element_name' of the None option and add it to your elementsToDisplay (It may be just "").
 
Last edited:
Debug $this->groupByHeadings to get the 'element_name' of the None option and add it to your elementsToDisplay (It may be just "").

Thanks @troester .
You were right for the empty quotes. The final working code to select specific elements on group including "None" to clear the group by previous selection in case someone else to want to try is:

PHP:
<?php if ($this->canGroupBy) : ?>
    <div class="col px-0">
        <?php
        $displayData = new stdClass;
        $displayData->icon = FabrikHelperHTML::icon('icon-list-view');
        $displayData->label = Text::_('COM_FABRIK_GROUP_BY');
        $displayData->links = array();

          $groupBysToDisplay = array('','vw_pm___EventName', 'vw_pm___Organization');

foreach ($this->groupByHeadings as $url => $obj) :
   
    if (in_array($obj->group_by, $groupBysToDisplay) || ($obj->group_by === 0)) :
       
        $label = ($obj->group_by === '') ? 'None' : $obj->label;
      
        $displayData->links[] = '<a class="nav-link" data-groupby="' . $obj->group_by . '" href="' . $url . '">' . $label . '</a>';
    endif;
endforeach;

                    $layout = $this->getModel()->getLayout('fabrik-nav-dropdown');
                    echo $layout->render($displayData);
                    ?>
                </div>
            <?php endif;

I consider Group By function a powerfull tool to generate reports from a single list combining different filters.

Something else I noticed and I dont know if i should post it here is that on Group by and extra ":" is added:

upload_2023-9-13_12-15-41.png


Maybe somewhere in the code but I don't know where :)
 
Last edited:
It's in components\com_fabrik\views\list\view.base.php
You can hack it (but it will be overriden by new versions).

I think it would be best to have it in an overridable layout file but it may be complicated (I assume there's also a js for ajax updates which has to be adapted etc.).
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top