Forums › Forums › OroCRM › OroCRM – How do I? Questions › Custom Contact List Grid
This topic contains 5 replies, has 2 voices, and was last updated by zhex900 6 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
- August 1, 2017 at 12:15 am #29347
- CreatorTopic
- AuthorReplies
- August 1, 2017 at 5:20 am #29348
Hi, @zhex900.
The predefined data views configures with views_list parameter of your grid config. The value of this parameter is the service that extended from Oro\Bundle\DataGridBundle\Extension\GridViews\AbstractViewsList abstract class.
This class have abstract function getViewsLis that returns an array of available views.
For your example, let’s add two new views to the contact grid.
The definition of the contacts grid available at crm/src/Oro/Bundle/ContactBundle/Resources/config/oro/datagrids.yml. The name of this datagrid is contacts-grid.As you can see, this datagrid config already have the views_list parameter with @oro_contact.contacts_view_list value. If you open this service (Oro\Bundle\ContactBundle\Datagrid\ContactsViewList class), you will see, that here we add the Duplicates view.
So, create new class ContactsExtraViewList somewhere in your bundle and extend it from the ContactsViewList. At this class, let’s rewrite getViewsList method and new views:
PHP1234567891011121314151617181920212223<?phpnamespace Acme\DemoBundle\Datagrid;use Oro\Bundle\ContactBundle\Datagrid\ContactsViewList;use Oro\Bundle\DataGridBundle\Extension\GridViews\View;class ContactExtraViewList extends ContactsViewList{/*** {@inheritdoc}*/protected function getViewsList(){$view1 = new View('oro_contact.one', ['firstName' => ['value' => 'foo', 'type' => '1']]);$view1->setLabel($this->translator->trans('the first custom view'));$view2 = new View('oro_contact.two', ['lastName' => ['value' => 'bar', 'type' => '1']]);$view2->setLabel($this->translator->trans('the second custom view'));return array_merge(parent::getViewsList(), [$view1, $view2]);}}At this example we add two new views. The first one has the filter by firstName field and ‘foo’ value, and the second one has the filter by lastName field with ‘bar’ value.
After that, you should register your class as service:
YAML1234your_bundle.contact_grid_view_list:class: Acme\DemoBundle\Datagridarguments:- @translatorAnd the last step is to change the views_list parameter for contacts-grid datagrid. To do this, add
Resources/config/oro/datagrids.yml file at your bundle with content:YAML123datagrids:contacts-grid:views_list: @your_bundle.contact_grid_view_listAnd after the cache reset, you will have new two grid views:
August 2, 2017 at 3:13 am #29349Thank you! It worked. Another question. How do I filter owner column?
PHP12345678910111213protected function getViewsList(){/** @var User $owner */$owner = $this->tokenStorage->getToken()->getUser();file_put_contents('/tmp/a.log',$owner->getFirstName().' '.$owner->getLastName(), FILE_APPEND);$owner_view = new View('oro_contact.owner', ['owner' => ['value' => $owner->getFirstName().' '.$owner->getLastName(), 'type' => '1']]);$owner_view->setLabel($this->translator->trans('oro.contact.gridview.owner.label'));// $view2 = new View('oro_contact.two', ['lastName' => ['value' => 'bar', 'type' => '1']]);//$view2->setLabel($this->translator->trans('the second custom view'));return array_merge(parent::getViewsList(), [$owner_view]);//, $view2]);}August 2, 2017 at 4:02 am #29350Hi, @zhex900.
The owner field receive the entity id as the value.
So, your view will be like:
PHP1$owner_view = new View('oro_contact.owner', ['owner' => ['value' => $owner->getId(), 'type' => '1']]);You can easy test what value format support the filter. In the grid just set some value and see the ajax request data for the grid with this filter. For example, for the owner field the request will be like:
August 2, 2017 at 8:53 pm #29351One more question.
$followup_view->setColumnsData(['firstName' => ['order' => 1]]);
What is wrong with this line? I want to control what columns are displayed in the view.August 3, 2017 at 12:50 am #29352I have found the answer myself. FirstName should be replaced with first_name.
- AuthorReplies
The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.