OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – Programming Questions How to add columns to contact datagrid and change an order?

This topic contains 9 replies, has 4 voices, and was last updated by  Pedro Molina 6 years, 10 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
  • #33334

    klipach
    Participant

    I have clean installation of Orocrm with some user data. I created a ContactBundle in src directory do adjust templates to my needs. When i put datagrid.yml into my bundle i get error: “Datagrid source “Array” does not exist”. How can i add columns and change the order?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #33335

    Yevhen Shyshkin
    Participant

    Hello, klipach.

    Look’s like you set incorrect datagrid source type parameter. Could you, please, put your datagrid configuration here?

    #33336

    Alexandr Smaga
    Participant

    Hello @klipach

    Please take a look to our standalone package, there is an example how bundle could be extended, how datagrid could be modified. And also take a look to event listener that changes columns order.

    #33337

    klipach
    Participant

    Is there some where an example how can i change columns order and add columns in Customers grid (or any other grid)?

    #33338

    Yevhen Shyshkin
    Participant

    Basic solution for that is to create listener on buildBefore that will update datagrid configuration – there you can customize ordering and add other columns.
    Listener example: https://github.com/orocrm/crm/blob/master/src/OroCRM/Bundle/CallBundle/EventListener/Datagrid/CallListener.php

    Advanced way is to extend datagrid, update it and reuse in your bundle.
    Configuration example: https://github.com/orocrm/crm/blob/master/src/OroCRM/Bundle/ContactBundle/Resources/config/datagrid.yml#L345

    #33339

    klipach
    Participant

    Thank you for a reply, as i understand if i want to modify contacts-grid i can do it only via listener?
    I need to show middleName, address and city.

    I found a way how to remove columns from datagrid but can’t add new one. Can you give me a hint how to do it? Here is my Listener:

    #33340

    Yevhen Shyshkin
    Participant

    You should add column to query builder select and add columns configuration with sorters and filters.

    I’d recommend you to do it in datagrid.yml in ContactBundle first just to find out and test how it should look like, and then do exactly the same thing from listener.

    Here is example if such listener https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/WorkflowBundle/Datagrid/WorkflowStepColumnListener.php#L131 – don’t look at business logic, just try to find how configuration is modified.

    #33341

    klipach
    Participant

    Thank you, did it. And how i can change the order of columns in the listener?

    #33342

    Yevhen Shyshkin
    Participant

    You simply have to put columns in correct order – f.e. you can use array_splice to inject your column in the middle of configuration. Simple example (without array_splice) can be found here https://github.com/orocrm/OroCRMMagentoContactUsBundle/blob/master/Datagrid/ContactRequestDatagridHelper.php.

    #33343

    Pedro Molina
    Participant

    Hi, how did you manage to add columns? i still dont get to do that with this method. I have this code to add some columns, but cant add certain columns to case grid and im unable to apply a method in the “field” value, for example:
    I need to show the “fullName” of related contact column of the case datagrid, that is a concatenation of first name and last name. Here is my code, if anyone can help me:

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

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top