OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

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.

  • Creator
    Topic
  • #29347

    zhex900
    Participant

    Hi,

    I know custom Contact list grid can be saved through the frontend GUI. How do I add a custom grid via code?

    Screen_Shot_2017_08_01_at_5_13_19_pm

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #29348

    Yurii Muratov
    Participant

    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:

    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:

    And 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:

    And after the cache reset, you will have new two grid views:

    #29349

    zhex900
    Participant

    Thank you! It worked. Another question. How do I filter owner column?

    #29350

    Yurii Muratov
    Participant

    Hi, @zhex900.

    The owner field receive the entity id as the value.

    So, your view will be like:

    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:

    screen

    #29351

    zhex900
    Participant

    One 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.

    #29352

    zhex900
    Participant

    I have found the answer myself. FirstName should be replaced with first_name.

Viewing 5 replies - 1 through 5 (of 5 total)

The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.

Back to top