How to show a custom grid in a custom tab in product edit page admin Magento-2 Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Magento 2 : How to add product grid in custom module's tabAdd custom grid to custom tab in admin panelDisplay problem for my custom tab in ADD/EDIT product page (admin)How to add Custom Model Grid Into Custom Tab in Product Edit page in admin panel in magento?How to add product grid in custom module tabI need to add a custom tab in catalog edit page of admin and need to display a custom grid collection under the tab in magento2.1.1 versionMagento 1.9 product edit page add tab and grid inside that tabMagento 2 (2.2) add custom tab for simple product only in adminAdd tab in product edit page in magento2?How to add tab in product Edit Page in Magento2?Magento 2 : How To Create Custom Grid in Product View

If Windows 7 doesn't support WSL, then what does Linux subsystem option mean?

How do I find out the mythology and history of my Fortress?

How were pictures turned from film to a big picture in a picture frame before digital scanning?

How often does castling occur in grandmaster games?

Effects on objects due to a brief relocation of massive amounts of mass

What is this clumpy 20-30cm high yellow-flowered plant?

Why does the remaining Rebel fleet at the end of Rogue One seem dramatically larger than the one in A New Hope?

Dating a Former Employee

Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?

ArcGIS Pro Python arcpy.CreatePersonalGDB_management

How much damage would a cupful of neutron star matter do to the Earth?

Why do we bend a book to keep it straight?

Taylor expansion of ln(1-x)

How does Python know the values already stored in its memory?

Chinese Seal on silk painting - what does it mean?

Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode

How can I reduce the gap between left and right of cdot with a macro?

What is the difference between globalisation and imperialism?

Illegal assignment from sObject to Id

When a candle burns, why does the top of wick glow if bottom of flame is hottest?

Time to Settle Down!

Performance gap between vector<bool> and array

What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?

A term for a woman complaining about things/begging in a cute/childish way



How to show a custom grid in a custom tab in product edit page admin Magento-2



Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Magento 2 : How to add product grid in custom module's tabAdd custom grid to custom tab in admin panelDisplay problem for my custom tab in ADD/EDIT product page (admin)How to add Custom Model Grid Into Custom Tab in Product Edit page in admin panel in magento?How to add product grid in custom module tabI need to add a custom tab in catalog edit page of admin and need to display a custom grid collection under the tab in magento2.1.1 versionMagento 1.9 product edit page add tab and grid inside that tabMagento 2 (2.2) add custom tab for simple product only in adminAdd tab in product edit page in magento2?How to add tab in product Edit Page in Magento2?Magento 2 : How To Create Custom Grid in Product View



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















How to add a custom grid in a new tab in product edit page using UI_Component method?



This custom grid fetches collection from a custom table.










share|improve this question
























  • Did you try anything? If so please share code.

    – P_U
    Mar 6 '18 at 11:08











  • For this link, i hope it will work for you. magento.stackexchange.com/questions/105036/…

    – KamranKhan
    Mar 6 '18 at 11:12











  • Follow this link i hope it will work for you. magento.stackexchange.com/questions/105036/…

    – KamranKhan
    Mar 6 '18 at 11:18











  • @ams codextblog.com/magento-2/… this link will help you

    – senthil
    Apr 8 at 13:34

















0















How to add a custom grid in a new tab in product edit page using UI_Component method?



This custom grid fetches collection from a custom table.










share|improve this question
























  • Did you try anything? If so please share code.

    – P_U
    Mar 6 '18 at 11:08











  • For this link, i hope it will work for you. magento.stackexchange.com/questions/105036/…

    – KamranKhan
    Mar 6 '18 at 11:12











  • Follow this link i hope it will work for you. magento.stackexchange.com/questions/105036/…

    – KamranKhan
    Mar 6 '18 at 11:18











  • @ams codextblog.com/magento-2/… this link will help you

    – senthil
    Apr 8 at 13:34













0












0








0








How to add a custom grid in a new tab in product edit page using UI_Component method?



This custom grid fetches collection from a custom table.










share|improve this question
















How to add a custom grid in a new tab in product edit page using UI_Component method?



This custom grid fetches collection from a custom table.







product adminhtml magento2.2 catalog product-grid






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 4:04









Teja Bhagavan Kollepara

2,99241949




2,99241949










asked Mar 6 '18 at 10:02









amsams

137




137












  • Did you try anything? If so please share code.

    – P_U
    Mar 6 '18 at 11:08











  • For this link, i hope it will work for you. magento.stackexchange.com/questions/105036/…

    – KamranKhan
    Mar 6 '18 at 11:12











  • Follow this link i hope it will work for you. magento.stackexchange.com/questions/105036/…

    – KamranKhan
    Mar 6 '18 at 11:18











  • @ams codextblog.com/magento-2/… this link will help you

    – senthil
    Apr 8 at 13:34

















  • Did you try anything? If so please share code.

    – P_U
    Mar 6 '18 at 11:08











  • For this link, i hope it will work for you. magento.stackexchange.com/questions/105036/…

    – KamranKhan
    Mar 6 '18 at 11:12











  • Follow this link i hope it will work for you. magento.stackexchange.com/questions/105036/…

    – KamranKhan
    Mar 6 '18 at 11:18











  • @ams codextblog.com/magento-2/… this link will help you

    – senthil
    Apr 8 at 13:34
















Did you try anything? If so please share code.

– P_U
Mar 6 '18 at 11:08





Did you try anything? If so please share code.

– P_U
Mar 6 '18 at 11:08













For this link, i hope it will work for you. magento.stackexchange.com/questions/105036/…

– KamranKhan
Mar 6 '18 at 11:12





For this link, i hope it will work for you. magento.stackexchange.com/questions/105036/…

– KamranKhan
Mar 6 '18 at 11:12













Follow this link i hope it will work for you. magento.stackexchange.com/questions/105036/…

– KamranKhan
Mar 6 '18 at 11:18





Follow this link i hope it will work for you. magento.stackexchange.com/questions/105036/…

– KamranKhan
Mar 6 '18 at 11:18













@ams codextblog.com/magento-2/… this link will help you

– senthil
Apr 8 at 13:34





@ams codextblog.com/magento-2/… this link will help you

– senthil
Apr 8 at 13:34










1 Answer
1






active

oldest

votes


















1














You can add it using modifier and UI component. Let's say my module name is Codextblog/Customtab.



Add Modifier
app/code/Codextblog/Customtab/etc/adminhtml/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoCatalogUiDataProviderProductFormModifierPool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="custom-tab-with-content" xsi:type="array">
<item name="class" xsi:type="string">CodextblogCustomtabUiDataProviderProductFormModifierCustomTab</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</arguments>
</virtualType>
</config>


Add custom tab



<?php
namespace CodextblogCustomtabUiDataProviderProductFormModifier;

use MagentoCatalogModelLocatorLocatorInterface;
use MagentoCatalogUiDataProviderProductFormModifierAbstractModifier;
use MagentoFrameworkStdlibArrayManager;
use MagentoFrameworkUrlInterface;
use MagentoUiComponentContainer;
use MagentoUiComponentFormFieldset;


class CustomTab extends AbstractModifier


const SAMPLE_FIELDSET_NAME = 'custom_fieldset';
const SAMPLE_FIELD_NAME = 'is_custom';


protected $_backendUrl;
protected $_productloader;
protected $_modelCustomtabFactory;

/**
* @var MagentoCatalogModelLocatorLocatorInterface
*/
protected $locator;

/**
* @var ArrayManager
*/
protected $arrayManager;

/**
* @var UrlInterface
*/
protected $urlBuilder;

/**
* @var array
*/
protected $meta = [];

/**
* @param LocatorInterface $locator
* @param ArrayManager $arrayManager
* @param UrlInterface $urlBuilder
*/
public function __construct(
LocatorInterface $locator,
ArrayManager $arrayManager,
UrlInterface $urlBuilder,
MagentoCatalogModelProductFactory $_productloader,
MagentoBackendModelUrlInterface $backendUrl
)
$this->locator = $locator;
$this->arrayManager = $arrayManager;
$this->urlBuilder = $urlBuilder;
$this->_productloader = $_productloader;
$this->_backendUrl = $backendUrl;


public function modifyData(array $data)

return $data;


public function modifyMeta(array $meta)

$this->meta = $meta;
$this->addCustomTab();

return $this->meta;


protected function addCustomTab()

$this->meta = array_merge_recursive(
$this->meta,
[
static::SAMPLE_FIELDSET_NAME => $this->getTabConfig(),
]
);


protected function getTabConfig()

return [
'arguments' => [
'data' => [
'config' => [
'label' => __('Custom Tab'),
'componentType' => Fieldset::NAME,
'dataScope' => '',
'provider' => static::FORM_NAME . '.product_form_data_source',
'ns' => static::FORM_NAME,
'collapsible' => true,
],
],
],
'children' => [
static::SAMPLE_FIELD_NAME => [
'arguments' => [
'data' => [
'config' => [
'autoRender' => true,
'componentType' => 'insertListing',
'dataScope' => 'custom_listing',
'externalProvider' => 'custom_listing.custom_listing_data_source',
'selectionsProvider' => 'custom_listing.custom_listing.product_columns.ids',
'ns' => 'custom_listing',
'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
'realTimeLink' => false,
'behaviourType' => 'simple',
'externalFilterMode' => true,
'imports' => [
'productId' => '$ $.provider :data.product.current_product_id'
],
'exports' => [
'productId' => '$ $.externalProvider :params.current_product_id'
],

],
],
],
'children' => [],
],
],
];





Add dataprovider file app/code/Codextblog/Customtab/Ui/Dataprovider/Product/CustomDataProvider.php



<?php

namespace CodextblogCustomtabUiDataProviderProduct;

use MagentoFrameworkAppRequestInterface;
use MagentoUiDataProviderAbstractDataProvider;
use CodextblogCustomModelResourceModelCustomCollectionFactory;
use CodextblogCustomModelResourceModelCustomCollection;
use CodextblogCustomModelCustom;


class CustomDataProvider extends AbstractDataProvider

/**
* @var CollectionFactory
*/
protected $collectionFactory;

/**
* @var RequestInterface
*/
protected $request;

/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param RequestInterface $request
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $collectionFactory,
RequestInterface $request,
array $meta = [],
array $data = []
)
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->collectionFactory = $collectionFactory;
$this->collection = $this->collectionFactory->create();
$this->request = $request;


/**
* @inheritdoc
*/
public function getData()

$this->getCollection();

$arrItems = [
'totalRecords' => $this->getCollection()->getSize(),
'items' => [],
];

foreach ($this->getCollection() as $item)
$arrItems['items'][] = $item->toArray([]);


return $arrItems;


/**
* @inheritdoc
*/
public function addFilter(MagentoFrameworkApiFilter $filter)

$field = $filter->getField();



if (in_array($field, ['title', 'nickname', 'detail']))
$filter->setField($field);


parent::addFilter($filter);




Here CodextblogCustomModelResourceModelCustomCollectionFactory is the collection of a module which grid will be display in a custom tab.



Create ui component app/code/Codextblog/Customtab/view/adminhtml/ui_component/custom_listing.xml



<?xml version="1.0" encoding="UTF-8"?>

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">custom_listing.custom_listing_data_source</item>
<item name="deps" xsi:type="string">custom_listing.custom_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">custom_columns</item>
</argument>
<dataSource name="custom_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">CodextblogCustomtabUiDataProviderProductCustomDataProvider</argument>
<argument name="name" xsi:type="string">custom_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="cacheRequests" xsi:type="boolean">false</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<listingToolbar name="listing_top">
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="statefull" xsi:type="array">
<item name="applied" xsi:type="boolean">false</item>
</item>
<item name="params" xsi:type="array">
<item name="filters_modifier" xsi:type="array"/>
</item>
</item>
</argument>
</filters>
<paging name="listing_paging"/>
</listingToolbar>
<columns name="custom_columns" class="MagentoUiComponentListingColumns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="childDefaults" xsi:type="array">
<item name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">customGrid</item>
<item name="target" xsi:type="string">selectReview</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">$ $.$data.rowIndex </item>
</item>
</item>
</item>
</item>
</argument>
<column name="id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" xsi:type="string" translate="true">ID</item>
<item name="sortOrder" xsi:type="number">0</item>
</item>
</argument>
</column>
<column name="name">
<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">Name</item>
<item name="sortOrder" xsi:type="number">30</item>
<item name="truncate" xsi:type="number">50</item>
<item name="nl2br" xsi:type="boolean">true</item>
<item name="escape" xsi:type="boolean">true</item>
</item>
</argument>
</column>
</columns>
</listing>





share|improve this answer

























  • I need the the custom table collection based on the product_id, in that collection how can i add current product id for the collection filter(CustomDataProvider.php)

    – senthil
    Apr 8 at 14:03












  • @senthil Did you try this $this->getRequest()->getParam('id');

    – chirag dodia
    Apr 9 at 4:46











  • Yes, but i am getting the following error. Fatal error: Method MagentoUiTemplateEngineXhtmlResult::__toString() must not throw an exception, caught Error: Call to undefined method LearnProductQAUiDataProviderProductQuestionAnswerDataProvider::getRequest() in D:workspaceMagentom226vendormagentomodule-uiControllerAdminhtmlIndexRender.php on line 0 So, instead of that i used the $this->_request->getParams(), but in this i don't see any product_id, because the grid load by ajax

    – senthil
    Apr 9 at 5:19












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f216161%2fhow-to-show-a-custom-grid-in-a-custom-tab-in-product-edit-page-admin-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can add it using modifier and UI component. Let's say my module name is Codextblog/Customtab.



Add Modifier
app/code/Codextblog/Customtab/etc/adminhtml/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoCatalogUiDataProviderProductFormModifierPool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="custom-tab-with-content" xsi:type="array">
<item name="class" xsi:type="string">CodextblogCustomtabUiDataProviderProductFormModifierCustomTab</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</arguments>
</virtualType>
</config>


Add custom tab



<?php
namespace CodextblogCustomtabUiDataProviderProductFormModifier;

use MagentoCatalogModelLocatorLocatorInterface;
use MagentoCatalogUiDataProviderProductFormModifierAbstractModifier;
use MagentoFrameworkStdlibArrayManager;
use MagentoFrameworkUrlInterface;
use MagentoUiComponentContainer;
use MagentoUiComponentFormFieldset;


class CustomTab extends AbstractModifier


const SAMPLE_FIELDSET_NAME = 'custom_fieldset';
const SAMPLE_FIELD_NAME = 'is_custom';


protected $_backendUrl;
protected $_productloader;
protected $_modelCustomtabFactory;

/**
* @var MagentoCatalogModelLocatorLocatorInterface
*/
protected $locator;

/**
* @var ArrayManager
*/
protected $arrayManager;

/**
* @var UrlInterface
*/
protected $urlBuilder;

/**
* @var array
*/
protected $meta = [];

/**
* @param LocatorInterface $locator
* @param ArrayManager $arrayManager
* @param UrlInterface $urlBuilder
*/
public function __construct(
LocatorInterface $locator,
ArrayManager $arrayManager,
UrlInterface $urlBuilder,
MagentoCatalogModelProductFactory $_productloader,
MagentoBackendModelUrlInterface $backendUrl
)
$this->locator = $locator;
$this->arrayManager = $arrayManager;
$this->urlBuilder = $urlBuilder;
$this->_productloader = $_productloader;
$this->_backendUrl = $backendUrl;


public function modifyData(array $data)

return $data;


public function modifyMeta(array $meta)

$this->meta = $meta;
$this->addCustomTab();

return $this->meta;


protected function addCustomTab()

$this->meta = array_merge_recursive(
$this->meta,
[
static::SAMPLE_FIELDSET_NAME => $this->getTabConfig(),
]
);


protected function getTabConfig()

return [
'arguments' => [
'data' => [
'config' => [
'label' => __('Custom Tab'),
'componentType' => Fieldset::NAME,
'dataScope' => '',
'provider' => static::FORM_NAME . '.product_form_data_source',
'ns' => static::FORM_NAME,
'collapsible' => true,
],
],
],
'children' => [
static::SAMPLE_FIELD_NAME => [
'arguments' => [
'data' => [
'config' => [
'autoRender' => true,
'componentType' => 'insertListing',
'dataScope' => 'custom_listing',
'externalProvider' => 'custom_listing.custom_listing_data_source',
'selectionsProvider' => 'custom_listing.custom_listing.product_columns.ids',
'ns' => 'custom_listing',
'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
'realTimeLink' => false,
'behaviourType' => 'simple',
'externalFilterMode' => true,
'imports' => [
'productId' => '$ $.provider :data.product.current_product_id'
],
'exports' => [
'productId' => '$ $.externalProvider :params.current_product_id'
],

],
],
],
'children' => [],
],
],
];





Add dataprovider file app/code/Codextblog/Customtab/Ui/Dataprovider/Product/CustomDataProvider.php



<?php

namespace CodextblogCustomtabUiDataProviderProduct;

use MagentoFrameworkAppRequestInterface;
use MagentoUiDataProviderAbstractDataProvider;
use CodextblogCustomModelResourceModelCustomCollectionFactory;
use CodextblogCustomModelResourceModelCustomCollection;
use CodextblogCustomModelCustom;


class CustomDataProvider extends AbstractDataProvider

/**
* @var CollectionFactory
*/
protected $collectionFactory;

/**
* @var RequestInterface
*/
protected $request;

/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param RequestInterface $request
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $collectionFactory,
RequestInterface $request,
array $meta = [],
array $data = []
)
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->collectionFactory = $collectionFactory;
$this->collection = $this->collectionFactory->create();
$this->request = $request;


/**
* @inheritdoc
*/
public function getData()

$this->getCollection();

$arrItems = [
'totalRecords' => $this->getCollection()->getSize(),
'items' => [],
];

foreach ($this->getCollection() as $item)
$arrItems['items'][] = $item->toArray([]);


return $arrItems;


/**
* @inheritdoc
*/
public function addFilter(MagentoFrameworkApiFilter $filter)

$field = $filter->getField();



if (in_array($field, ['title', 'nickname', 'detail']))
$filter->setField($field);


parent::addFilter($filter);




Here CodextblogCustomModelResourceModelCustomCollectionFactory is the collection of a module which grid will be display in a custom tab.



Create ui component app/code/Codextblog/Customtab/view/adminhtml/ui_component/custom_listing.xml



<?xml version="1.0" encoding="UTF-8"?>

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">custom_listing.custom_listing_data_source</item>
<item name="deps" xsi:type="string">custom_listing.custom_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">custom_columns</item>
</argument>
<dataSource name="custom_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">CodextblogCustomtabUiDataProviderProductCustomDataProvider</argument>
<argument name="name" xsi:type="string">custom_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="cacheRequests" xsi:type="boolean">false</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<listingToolbar name="listing_top">
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="statefull" xsi:type="array">
<item name="applied" xsi:type="boolean">false</item>
</item>
<item name="params" xsi:type="array">
<item name="filters_modifier" xsi:type="array"/>
</item>
</item>
</argument>
</filters>
<paging name="listing_paging"/>
</listingToolbar>
<columns name="custom_columns" class="MagentoUiComponentListingColumns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="childDefaults" xsi:type="array">
<item name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">customGrid</item>
<item name="target" xsi:type="string">selectReview</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">$ $.$data.rowIndex </item>
</item>
</item>
</item>
</item>
</argument>
<column name="id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" xsi:type="string" translate="true">ID</item>
<item name="sortOrder" xsi:type="number">0</item>
</item>
</argument>
</column>
<column name="name">
<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">Name</item>
<item name="sortOrder" xsi:type="number">30</item>
<item name="truncate" xsi:type="number">50</item>
<item name="nl2br" xsi:type="boolean">true</item>
<item name="escape" xsi:type="boolean">true</item>
</item>
</argument>
</column>
</columns>
</listing>





share|improve this answer

























  • I need the the custom table collection based on the product_id, in that collection how can i add current product id for the collection filter(CustomDataProvider.php)

    – senthil
    Apr 8 at 14:03












  • @senthil Did you try this $this->getRequest()->getParam('id');

    – chirag dodia
    Apr 9 at 4:46











  • Yes, but i am getting the following error. Fatal error: Method MagentoUiTemplateEngineXhtmlResult::__toString() must not throw an exception, caught Error: Call to undefined method LearnProductQAUiDataProviderProductQuestionAnswerDataProvider::getRequest() in D:workspaceMagentom226vendormagentomodule-uiControllerAdminhtmlIndexRender.php on line 0 So, instead of that i used the $this->_request->getParams(), but in this i don't see any product_id, because the grid load by ajax

    – senthil
    Apr 9 at 5:19
















1














You can add it using modifier and UI component. Let's say my module name is Codextblog/Customtab.



Add Modifier
app/code/Codextblog/Customtab/etc/adminhtml/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoCatalogUiDataProviderProductFormModifierPool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="custom-tab-with-content" xsi:type="array">
<item name="class" xsi:type="string">CodextblogCustomtabUiDataProviderProductFormModifierCustomTab</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</arguments>
</virtualType>
</config>


Add custom tab



<?php
namespace CodextblogCustomtabUiDataProviderProductFormModifier;

use MagentoCatalogModelLocatorLocatorInterface;
use MagentoCatalogUiDataProviderProductFormModifierAbstractModifier;
use MagentoFrameworkStdlibArrayManager;
use MagentoFrameworkUrlInterface;
use MagentoUiComponentContainer;
use MagentoUiComponentFormFieldset;


class CustomTab extends AbstractModifier


const SAMPLE_FIELDSET_NAME = 'custom_fieldset';
const SAMPLE_FIELD_NAME = 'is_custom';


protected $_backendUrl;
protected $_productloader;
protected $_modelCustomtabFactory;

/**
* @var MagentoCatalogModelLocatorLocatorInterface
*/
protected $locator;

/**
* @var ArrayManager
*/
protected $arrayManager;

/**
* @var UrlInterface
*/
protected $urlBuilder;

/**
* @var array
*/
protected $meta = [];

/**
* @param LocatorInterface $locator
* @param ArrayManager $arrayManager
* @param UrlInterface $urlBuilder
*/
public function __construct(
LocatorInterface $locator,
ArrayManager $arrayManager,
UrlInterface $urlBuilder,
MagentoCatalogModelProductFactory $_productloader,
MagentoBackendModelUrlInterface $backendUrl
)
$this->locator = $locator;
$this->arrayManager = $arrayManager;
$this->urlBuilder = $urlBuilder;
$this->_productloader = $_productloader;
$this->_backendUrl = $backendUrl;


public function modifyData(array $data)

return $data;


public function modifyMeta(array $meta)

$this->meta = $meta;
$this->addCustomTab();

return $this->meta;


protected function addCustomTab()

$this->meta = array_merge_recursive(
$this->meta,
[
static::SAMPLE_FIELDSET_NAME => $this->getTabConfig(),
]
);


protected function getTabConfig()

return [
'arguments' => [
'data' => [
'config' => [
'label' => __('Custom Tab'),
'componentType' => Fieldset::NAME,
'dataScope' => '',
'provider' => static::FORM_NAME . '.product_form_data_source',
'ns' => static::FORM_NAME,
'collapsible' => true,
],
],
],
'children' => [
static::SAMPLE_FIELD_NAME => [
'arguments' => [
'data' => [
'config' => [
'autoRender' => true,
'componentType' => 'insertListing',
'dataScope' => 'custom_listing',
'externalProvider' => 'custom_listing.custom_listing_data_source',
'selectionsProvider' => 'custom_listing.custom_listing.product_columns.ids',
'ns' => 'custom_listing',
'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
'realTimeLink' => false,
'behaviourType' => 'simple',
'externalFilterMode' => true,
'imports' => [
'productId' => '$ $.provider :data.product.current_product_id'
],
'exports' => [
'productId' => '$ $.externalProvider :params.current_product_id'
],

],
],
],
'children' => [],
],
],
];





Add dataprovider file app/code/Codextblog/Customtab/Ui/Dataprovider/Product/CustomDataProvider.php



<?php

namespace CodextblogCustomtabUiDataProviderProduct;

use MagentoFrameworkAppRequestInterface;
use MagentoUiDataProviderAbstractDataProvider;
use CodextblogCustomModelResourceModelCustomCollectionFactory;
use CodextblogCustomModelResourceModelCustomCollection;
use CodextblogCustomModelCustom;


class CustomDataProvider extends AbstractDataProvider

/**
* @var CollectionFactory
*/
protected $collectionFactory;

/**
* @var RequestInterface
*/
protected $request;

/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param RequestInterface $request
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $collectionFactory,
RequestInterface $request,
array $meta = [],
array $data = []
)
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->collectionFactory = $collectionFactory;
$this->collection = $this->collectionFactory->create();
$this->request = $request;


/**
* @inheritdoc
*/
public function getData()

$this->getCollection();

$arrItems = [
'totalRecords' => $this->getCollection()->getSize(),
'items' => [],
];

foreach ($this->getCollection() as $item)
$arrItems['items'][] = $item->toArray([]);


return $arrItems;


/**
* @inheritdoc
*/
public function addFilter(MagentoFrameworkApiFilter $filter)

$field = $filter->getField();



if (in_array($field, ['title', 'nickname', 'detail']))
$filter->setField($field);


parent::addFilter($filter);




Here CodextblogCustomModelResourceModelCustomCollectionFactory is the collection of a module which grid will be display in a custom tab.



Create ui component app/code/Codextblog/Customtab/view/adminhtml/ui_component/custom_listing.xml



<?xml version="1.0" encoding="UTF-8"?>

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">custom_listing.custom_listing_data_source</item>
<item name="deps" xsi:type="string">custom_listing.custom_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">custom_columns</item>
</argument>
<dataSource name="custom_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">CodextblogCustomtabUiDataProviderProductCustomDataProvider</argument>
<argument name="name" xsi:type="string">custom_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="cacheRequests" xsi:type="boolean">false</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<listingToolbar name="listing_top">
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="statefull" xsi:type="array">
<item name="applied" xsi:type="boolean">false</item>
</item>
<item name="params" xsi:type="array">
<item name="filters_modifier" xsi:type="array"/>
</item>
</item>
</argument>
</filters>
<paging name="listing_paging"/>
</listingToolbar>
<columns name="custom_columns" class="MagentoUiComponentListingColumns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="childDefaults" xsi:type="array">
<item name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">customGrid</item>
<item name="target" xsi:type="string">selectReview</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">$ $.$data.rowIndex </item>
</item>
</item>
</item>
</item>
</argument>
<column name="id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" xsi:type="string" translate="true">ID</item>
<item name="sortOrder" xsi:type="number">0</item>
</item>
</argument>
</column>
<column name="name">
<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">Name</item>
<item name="sortOrder" xsi:type="number">30</item>
<item name="truncate" xsi:type="number">50</item>
<item name="nl2br" xsi:type="boolean">true</item>
<item name="escape" xsi:type="boolean">true</item>
</item>
</argument>
</column>
</columns>
</listing>





share|improve this answer

























  • I need the the custom table collection based on the product_id, in that collection how can i add current product id for the collection filter(CustomDataProvider.php)

    – senthil
    Apr 8 at 14:03












  • @senthil Did you try this $this->getRequest()->getParam('id');

    – chirag dodia
    Apr 9 at 4:46











  • Yes, but i am getting the following error. Fatal error: Method MagentoUiTemplateEngineXhtmlResult::__toString() must not throw an exception, caught Error: Call to undefined method LearnProductQAUiDataProviderProductQuestionAnswerDataProvider::getRequest() in D:workspaceMagentom226vendormagentomodule-uiControllerAdminhtmlIndexRender.php on line 0 So, instead of that i used the $this->_request->getParams(), but in this i don't see any product_id, because the grid load by ajax

    – senthil
    Apr 9 at 5:19














1












1








1







You can add it using modifier and UI component. Let's say my module name is Codextblog/Customtab.



Add Modifier
app/code/Codextblog/Customtab/etc/adminhtml/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoCatalogUiDataProviderProductFormModifierPool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="custom-tab-with-content" xsi:type="array">
<item name="class" xsi:type="string">CodextblogCustomtabUiDataProviderProductFormModifierCustomTab</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</arguments>
</virtualType>
</config>


Add custom tab



<?php
namespace CodextblogCustomtabUiDataProviderProductFormModifier;

use MagentoCatalogModelLocatorLocatorInterface;
use MagentoCatalogUiDataProviderProductFormModifierAbstractModifier;
use MagentoFrameworkStdlibArrayManager;
use MagentoFrameworkUrlInterface;
use MagentoUiComponentContainer;
use MagentoUiComponentFormFieldset;


class CustomTab extends AbstractModifier


const SAMPLE_FIELDSET_NAME = 'custom_fieldset';
const SAMPLE_FIELD_NAME = 'is_custom';


protected $_backendUrl;
protected $_productloader;
protected $_modelCustomtabFactory;

/**
* @var MagentoCatalogModelLocatorLocatorInterface
*/
protected $locator;

/**
* @var ArrayManager
*/
protected $arrayManager;

/**
* @var UrlInterface
*/
protected $urlBuilder;

/**
* @var array
*/
protected $meta = [];

/**
* @param LocatorInterface $locator
* @param ArrayManager $arrayManager
* @param UrlInterface $urlBuilder
*/
public function __construct(
LocatorInterface $locator,
ArrayManager $arrayManager,
UrlInterface $urlBuilder,
MagentoCatalogModelProductFactory $_productloader,
MagentoBackendModelUrlInterface $backendUrl
)
$this->locator = $locator;
$this->arrayManager = $arrayManager;
$this->urlBuilder = $urlBuilder;
$this->_productloader = $_productloader;
$this->_backendUrl = $backendUrl;


public function modifyData(array $data)

return $data;


public function modifyMeta(array $meta)

$this->meta = $meta;
$this->addCustomTab();

return $this->meta;


protected function addCustomTab()

$this->meta = array_merge_recursive(
$this->meta,
[
static::SAMPLE_FIELDSET_NAME => $this->getTabConfig(),
]
);


protected function getTabConfig()

return [
'arguments' => [
'data' => [
'config' => [
'label' => __('Custom Tab'),
'componentType' => Fieldset::NAME,
'dataScope' => '',
'provider' => static::FORM_NAME . '.product_form_data_source',
'ns' => static::FORM_NAME,
'collapsible' => true,
],
],
],
'children' => [
static::SAMPLE_FIELD_NAME => [
'arguments' => [
'data' => [
'config' => [
'autoRender' => true,
'componentType' => 'insertListing',
'dataScope' => 'custom_listing',
'externalProvider' => 'custom_listing.custom_listing_data_source',
'selectionsProvider' => 'custom_listing.custom_listing.product_columns.ids',
'ns' => 'custom_listing',
'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
'realTimeLink' => false,
'behaviourType' => 'simple',
'externalFilterMode' => true,
'imports' => [
'productId' => '$ $.provider :data.product.current_product_id'
],
'exports' => [
'productId' => '$ $.externalProvider :params.current_product_id'
],

],
],
],
'children' => [],
],
],
];





Add dataprovider file app/code/Codextblog/Customtab/Ui/Dataprovider/Product/CustomDataProvider.php



<?php

namespace CodextblogCustomtabUiDataProviderProduct;

use MagentoFrameworkAppRequestInterface;
use MagentoUiDataProviderAbstractDataProvider;
use CodextblogCustomModelResourceModelCustomCollectionFactory;
use CodextblogCustomModelResourceModelCustomCollection;
use CodextblogCustomModelCustom;


class CustomDataProvider extends AbstractDataProvider

/**
* @var CollectionFactory
*/
protected $collectionFactory;

/**
* @var RequestInterface
*/
protected $request;

/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param RequestInterface $request
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $collectionFactory,
RequestInterface $request,
array $meta = [],
array $data = []
)
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->collectionFactory = $collectionFactory;
$this->collection = $this->collectionFactory->create();
$this->request = $request;


/**
* @inheritdoc
*/
public function getData()

$this->getCollection();

$arrItems = [
'totalRecords' => $this->getCollection()->getSize(),
'items' => [],
];

foreach ($this->getCollection() as $item)
$arrItems['items'][] = $item->toArray([]);


return $arrItems;


/**
* @inheritdoc
*/
public function addFilter(MagentoFrameworkApiFilter $filter)

$field = $filter->getField();



if (in_array($field, ['title', 'nickname', 'detail']))
$filter->setField($field);


parent::addFilter($filter);




Here CodextblogCustomModelResourceModelCustomCollectionFactory is the collection of a module which grid will be display in a custom tab.



Create ui component app/code/Codextblog/Customtab/view/adminhtml/ui_component/custom_listing.xml



<?xml version="1.0" encoding="UTF-8"?>

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">custom_listing.custom_listing_data_source</item>
<item name="deps" xsi:type="string">custom_listing.custom_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">custom_columns</item>
</argument>
<dataSource name="custom_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">CodextblogCustomtabUiDataProviderProductCustomDataProvider</argument>
<argument name="name" xsi:type="string">custom_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="cacheRequests" xsi:type="boolean">false</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<listingToolbar name="listing_top">
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="statefull" xsi:type="array">
<item name="applied" xsi:type="boolean">false</item>
</item>
<item name="params" xsi:type="array">
<item name="filters_modifier" xsi:type="array"/>
</item>
</item>
</argument>
</filters>
<paging name="listing_paging"/>
</listingToolbar>
<columns name="custom_columns" class="MagentoUiComponentListingColumns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="childDefaults" xsi:type="array">
<item name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">customGrid</item>
<item name="target" xsi:type="string">selectReview</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">$ $.$data.rowIndex </item>
</item>
</item>
</item>
</item>
</argument>
<column name="id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" xsi:type="string" translate="true">ID</item>
<item name="sortOrder" xsi:type="number">0</item>
</item>
</argument>
</column>
<column name="name">
<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">Name</item>
<item name="sortOrder" xsi:type="number">30</item>
<item name="truncate" xsi:type="number">50</item>
<item name="nl2br" xsi:type="boolean">true</item>
<item name="escape" xsi:type="boolean">true</item>
</item>
</argument>
</column>
</columns>
</listing>





share|improve this answer















You can add it using modifier and UI component. Let's say my module name is Codextblog/Customtab.



Add Modifier
app/code/Codextblog/Customtab/etc/adminhtml/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoCatalogUiDataProviderProductFormModifierPool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="custom-tab-with-content" xsi:type="array">
<item name="class" xsi:type="string">CodextblogCustomtabUiDataProviderProductFormModifierCustomTab</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</arguments>
</virtualType>
</config>


Add custom tab



<?php
namespace CodextblogCustomtabUiDataProviderProductFormModifier;

use MagentoCatalogModelLocatorLocatorInterface;
use MagentoCatalogUiDataProviderProductFormModifierAbstractModifier;
use MagentoFrameworkStdlibArrayManager;
use MagentoFrameworkUrlInterface;
use MagentoUiComponentContainer;
use MagentoUiComponentFormFieldset;


class CustomTab extends AbstractModifier


const SAMPLE_FIELDSET_NAME = 'custom_fieldset';
const SAMPLE_FIELD_NAME = 'is_custom';


protected $_backendUrl;
protected $_productloader;
protected $_modelCustomtabFactory;

/**
* @var MagentoCatalogModelLocatorLocatorInterface
*/
protected $locator;

/**
* @var ArrayManager
*/
protected $arrayManager;

/**
* @var UrlInterface
*/
protected $urlBuilder;

/**
* @var array
*/
protected $meta = [];

/**
* @param LocatorInterface $locator
* @param ArrayManager $arrayManager
* @param UrlInterface $urlBuilder
*/
public function __construct(
LocatorInterface $locator,
ArrayManager $arrayManager,
UrlInterface $urlBuilder,
MagentoCatalogModelProductFactory $_productloader,
MagentoBackendModelUrlInterface $backendUrl
)
$this->locator = $locator;
$this->arrayManager = $arrayManager;
$this->urlBuilder = $urlBuilder;
$this->_productloader = $_productloader;
$this->_backendUrl = $backendUrl;


public function modifyData(array $data)

return $data;


public function modifyMeta(array $meta)

$this->meta = $meta;
$this->addCustomTab();

return $this->meta;


protected function addCustomTab()

$this->meta = array_merge_recursive(
$this->meta,
[
static::SAMPLE_FIELDSET_NAME => $this->getTabConfig(),
]
);


protected function getTabConfig()

return [
'arguments' => [
'data' => [
'config' => [
'label' => __('Custom Tab'),
'componentType' => Fieldset::NAME,
'dataScope' => '',
'provider' => static::FORM_NAME . '.product_form_data_source',
'ns' => static::FORM_NAME,
'collapsible' => true,
],
],
],
'children' => [
static::SAMPLE_FIELD_NAME => [
'arguments' => [
'data' => [
'config' => [
'autoRender' => true,
'componentType' => 'insertListing',
'dataScope' => 'custom_listing',
'externalProvider' => 'custom_listing.custom_listing_data_source',
'selectionsProvider' => 'custom_listing.custom_listing.product_columns.ids',
'ns' => 'custom_listing',
'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
'realTimeLink' => false,
'behaviourType' => 'simple',
'externalFilterMode' => true,
'imports' => [
'productId' => '$ $.provider :data.product.current_product_id'
],
'exports' => [
'productId' => '$ $.externalProvider :params.current_product_id'
],

],
],
],
'children' => [],
],
],
];





Add dataprovider file app/code/Codextblog/Customtab/Ui/Dataprovider/Product/CustomDataProvider.php



<?php

namespace CodextblogCustomtabUiDataProviderProduct;

use MagentoFrameworkAppRequestInterface;
use MagentoUiDataProviderAbstractDataProvider;
use CodextblogCustomModelResourceModelCustomCollectionFactory;
use CodextblogCustomModelResourceModelCustomCollection;
use CodextblogCustomModelCustom;


class CustomDataProvider extends AbstractDataProvider

/**
* @var CollectionFactory
*/
protected $collectionFactory;

/**
* @var RequestInterface
*/
protected $request;

/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param RequestInterface $request
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $collectionFactory,
RequestInterface $request,
array $meta = [],
array $data = []
)
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->collectionFactory = $collectionFactory;
$this->collection = $this->collectionFactory->create();
$this->request = $request;


/**
* @inheritdoc
*/
public function getData()

$this->getCollection();

$arrItems = [
'totalRecords' => $this->getCollection()->getSize(),
'items' => [],
];

foreach ($this->getCollection() as $item)
$arrItems['items'][] = $item->toArray([]);


return $arrItems;


/**
* @inheritdoc
*/
public function addFilter(MagentoFrameworkApiFilter $filter)

$field = $filter->getField();



if (in_array($field, ['title', 'nickname', 'detail']))
$filter->setField($field);


parent::addFilter($filter);




Here CodextblogCustomModelResourceModelCustomCollectionFactory is the collection of a module which grid will be display in a custom tab.



Create ui component app/code/Codextblog/Customtab/view/adminhtml/ui_component/custom_listing.xml



<?xml version="1.0" encoding="UTF-8"?>

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">custom_listing.custom_listing_data_source</item>
<item name="deps" xsi:type="string">custom_listing.custom_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">custom_columns</item>
</argument>
<dataSource name="custom_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">CodextblogCustomtabUiDataProviderProductCustomDataProvider</argument>
<argument name="name" xsi:type="string">custom_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="cacheRequests" xsi:type="boolean">false</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<listingToolbar name="listing_top">
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="statefull" xsi:type="array">
<item name="applied" xsi:type="boolean">false</item>
</item>
<item name="params" xsi:type="array">
<item name="filters_modifier" xsi:type="array"/>
</item>
</item>
</argument>
</filters>
<paging name="listing_paging"/>
</listingToolbar>
<columns name="custom_columns" class="MagentoUiComponentListingColumns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="childDefaults" xsi:type="array">
<item name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">customGrid</item>
<item name="target" xsi:type="string">selectReview</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">$ $.$data.rowIndex </item>
</item>
</item>
</item>
</item>
</argument>
<column name="id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" xsi:type="string" translate="true">ID</item>
<item name="sortOrder" xsi:type="number">0</item>
</item>
</argument>
</column>
<column name="name">
<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">Name</item>
<item name="sortOrder" xsi:type="number">30</item>
<item name="truncate" xsi:type="number">50</item>
<item name="nl2br" xsi:type="boolean">true</item>
<item name="escape" xsi:type="boolean">true</item>
</item>
</argument>
</column>
</columns>
</listing>






share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 15 at 7:33









Marius

168k28324692




168k28324692










answered Apr 30 '18 at 7:28









chirag dodiachirag dodia

83931122




83931122












  • I need the the custom table collection based on the product_id, in that collection how can i add current product id for the collection filter(CustomDataProvider.php)

    – senthil
    Apr 8 at 14:03












  • @senthil Did you try this $this->getRequest()->getParam('id');

    – chirag dodia
    Apr 9 at 4:46











  • Yes, but i am getting the following error. Fatal error: Method MagentoUiTemplateEngineXhtmlResult::__toString() must not throw an exception, caught Error: Call to undefined method LearnProductQAUiDataProviderProductQuestionAnswerDataProvider::getRequest() in D:workspaceMagentom226vendormagentomodule-uiControllerAdminhtmlIndexRender.php on line 0 So, instead of that i used the $this->_request->getParams(), but in this i don't see any product_id, because the grid load by ajax

    – senthil
    Apr 9 at 5:19


















  • I need the the custom table collection based on the product_id, in that collection how can i add current product id for the collection filter(CustomDataProvider.php)

    – senthil
    Apr 8 at 14:03












  • @senthil Did you try this $this->getRequest()->getParam('id');

    – chirag dodia
    Apr 9 at 4:46











  • Yes, but i am getting the following error. Fatal error: Method MagentoUiTemplateEngineXhtmlResult::__toString() must not throw an exception, caught Error: Call to undefined method LearnProductQAUiDataProviderProductQuestionAnswerDataProvider::getRequest() in D:workspaceMagentom226vendormagentomodule-uiControllerAdminhtmlIndexRender.php on line 0 So, instead of that i used the $this->_request->getParams(), but in this i don't see any product_id, because the grid load by ajax

    – senthil
    Apr 9 at 5:19

















I need the the custom table collection based on the product_id, in that collection how can i add current product id for the collection filter(CustomDataProvider.php)

– senthil
Apr 8 at 14:03






I need the the custom table collection based on the product_id, in that collection how can i add current product id for the collection filter(CustomDataProvider.php)

– senthil
Apr 8 at 14:03














@senthil Did you try this $this->getRequest()->getParam('id');

– chirag dodia
Apr 9 at 4:46





@senthil Did you try this $this->getRequest()->getParam('id');

– chirag dodia
Apr 9 at 4:46













Yes, but i am getting the following error. Fatal error: Method MagentoUiTemplateEngineXhtmlResult::__toString() must not throw an exception, caught Error: Call to undefined method LearnProductQAUiDataProviderProductQuestionAnswerDataProvider::getRequest() in D:workspaceMagentom226vendormagentomodule-uiControllerAdminhtmlIndexRender.php on line 0 So, instead of that i used the $this->_request->getParams(), but in this i don't see any product_id, because the grid load by ajax

– senthil
Apr 9 at 5:19






Yes, but i am getting the following error. Fatal error: Method MagentoUiTemplateEngineXhtmlResult::__toString() must not throw an exception, caught Error: Call to undefined method LearnProductQAUiDataProviderProductQuestionAnswerDataProvider::getRequest() in D:workspaceMagentom226vendormagentomodule-uiControllerAdminhtmlIndexRender.php on line 0 So, instead of that i used the $this->_request->getParams(), but in this i don't see any product_id, because the grid load by ajax

– senthil
Apr 9 at 5:19


















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f216161%2fhow-to-show-a-custom-grid-in-a-custom-tab-in-product-edit-page-admin-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Sum ergo cogito? 1 nng

419 nièngy_Soadمي 19bal1.5o_g

Queiggey Chernihivv 9NnOo i Zw X QqKk LpB