Forums › Forums › OroCRM › OroCRM – Programming Questions › Sort and filter contacts by group
This topic contains 2 replies, has 1 voice, and was last updated by klipach 9 years, 4 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- October 22, 2014 at 5:25 am #24908
In Oro 1.2 there was a Group filter and sorter in contact grid. In version 1.3 it is removed. Implementation from version 1.2 doesn’t work due to a bug. How can i add this filter/sorter?
- CreatorTopic
- AuthorReplies
- November 4, 2014 at 4:44 am #24909
There is no answer for a long time… so i found some solution, it is not perfect but it works. You can add filter functionality by adding custom filter class. Here is an example:
GroupFilter.php
1234567891011121314151617181920212223242526272829303132<?phpnamespace Acme\DemoBundle\Filter;use Oro\Bundle\FilterBundle\Filter\EntityFilter;use Oro\Bundle\FilterBundle\Datasource\FilterDatasourceAdapterInterface;class GroupFilter extends EntityFilter{/*** {@inheritdoc}*/public function apply(FilterDatasourceAdapterInterface $ds, $data){$data = $this->parseData($data);if (!$data) {return false;}$i = 1;foreach ($data['value'] as $group) {$ds->getQueryBuilder()->andWhere('(:group' . $i . ' MEMBER OF c.groups )')->setParameter('group' . $i, $group->getId());$i++;}return true;}}Register this filter in filters.yml
1234567891011parameters:oro_filter.group_filter.class: Acme\DemoBundle\Filter\GroupFilterservices:oro_filter.group_filter:class: %oro_filter.group_filter.class%arguments:- @form.factory- @oro_filter.filter_utilitytags:- { name: oro_filter.extension.orm_filter.filter, type: group }don’t forget to load filters.yml in DependencyInjection/AcmeDemoExtension.php
now you can use this filter in contact datagrid using eventListener like here https://github.com/orocrm/crm/blob/master/src/OroCRM/Bundle/CallBundle/EventListener/Datagrid/CallListener.php like
12345678910111213141516171819$config->offsetSetByPath('[filters][columns][groupLabelsAsString]',array('type' => 'group','data_name' => 'contactGroup.id','enabled' => true,'options' =>array('field_options' =>array('class' => 'OroCRMContactBundle:Group','property' => 'label','multiple' => true,))));or in datagrid.yml
1234567891011groupLabelsAsString:type: groupdata_name: contactGroup.idenabled: trueoptions:field_options:class: OroCRMContactBundle:Groupproperty: labelmultiple: trueDecember 17, 2014 at 9:38 am #24910Is there a better way to do such filtering?
- AuthorReplies
The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.