I've created a new module with a number of foreign keys to base magento db tables, i want to add data from the magento table (customer_entity) into my custom grid.
I have a FK relationship connecting custom_entity "customer_id" to "entity_id" in customer_entity. I would like to show both the Name and Email address of the user in the custom entity grid, how do i do this?
I understand in Magento 1 you would override prepareCollection(), how do i do this in Magento 2?
I've added the following
protected function _renderFiltersBefore() {
$joinTable = $this->getTable('customer_entity');
$this->getSelect()->join($joinTable.' as customer','amrita_practitioner.customer_id = customer.entity_id', array('*'));
parent::_renderFiltersBefore();
}
and i'm trying to add the column as follows
<column name="email">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Email</item>
</item>
</argument>
</column>
Can anyone shed any light on this, i'm having a number of problems using multiple models in one module, and any help would be greatly appreciated.
Thanks,
Sophie
Best Answer
I believe you can display the foreign table values by defining a class in the admin_html/ui_component/YOUR_GRID_XML_FILE as follows (GIVEN EXAMPLE IS FOR ADMIN USER with Access as the name of the controller / model )
Once you have defined your user id field to a class we should create the file at the same path and form the data as follows:
The above will post the user name instead of user id.