Forums › Forums › OroPlatform › OroPlatform – Programming Questions › Datagrid Choice Filter with choices from a Column
This topic contains 9 replies, has 6 voices, and was last updated by Andrey Yatsenko 4 years, 8 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- June 1, 2016 at 2:40 am #34160
How is it possible to create a datagrid filter that contains distinct values from a column of the grid ?
- CreatorTopic
- AuthorReplies
- June 1, 2016 at 7:39 am #34161
Hi Dima,
Not sure I correctly understand your question. Would you mind to provide a concrete use case you’d like to achieve? Thank you.
June 2, 2016 at 5:34 am #34162Hi!
You should create custom provider, which return list of entities and configure QueryBuilder as you want.
PHP12345678910111213141516171819202122232425262728293031323334353637383940<?phpnamespace Custom\Bundle\CustomBundle\Provider;use Doctrine\Bundle\DoctrineBundle\Registry;class ChoiceProvider{/** @var Registry */protected $registry;/*** @param Registry $registry*/public function __construct(Registry $registry){$this->registry = $registry;}/*** @return array*/public function getList(){$results = [];$rows = $this->registry->getManager()->getRepository('Oro\Bundle\UserBundle\Entity\User')->createQueryBuilder('u')->getQuery()->getResult();foreach($rows as $entity) {$results[$entity->getId()] = $entity->getFirstname().' '.$entity->getLastname();}return $results;}}setup provider as service
YAML1234567parameters:oro_custom.provider.choice.class: Custom\Bundle\CustomBundle\Provider\ChoiceProvideroro_custom.provider.choice:class: %oro_custom.provider.choice.class%arguments:- '@doctrine'and configure your filter, something like this:
YAML12345678910my-grid:filters:customField:type: choicelabel: labeldata_name: a.customoptions:field_options:multiple: falsechoices: "@oro_custom.provider.choice->getList"June 2, 2016 at 5:41 am #34163Hi
Thank you for the quick reply. I think it won’t work with the provider. I need to get only the values/entities that are present in the datagrid resultset. But the filters are build before the datagrids datasource has the results.
June 2, 2016 at 6:52 am #34164You want to put to filter values from certain column only from current page, right?
June 3, 2016 at 1:00 am #34165Yes,
from current datagrid.July 27, 2016 at 12:12 am #34166@Mike
I needed this and it’s very well explained. Thank you!
August 2, 2016 at 11:59 pm #34167@Mike
As an added question, is it possible to pass a parameter to the getList() function? In my case the parameter is the same that I’m passing to my where clause in my datagrid (defined under bind_parameters).
July 5, 2019 at 10:47 pm #39912Hi
I have similar issue. I have a datagrid which on one of its columns, choices data must be loaded dynamically. I need to load them conditional according to passed parameter.YAML1234columns:targetName:label: peymans.finance.xero_tracking_category.target_entity.labelchoices: "@custom.finance->getCategoryOptionTargetFields"How can I pass parameter to method: “getCategoryOptionTargetFields()”?
Regards
July 8, 2019 at 1:46 am #39924Please have a look at datagrid listeners, they are more flexible than the configuration
https://github.com/oroinc/platform/blob/master/src/Oro/Bundle/DataGridBundle/Resources/doc/backend/events.md - AuthorReplies
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.