Magento2 send ID insertListing to gridHow can i rewrite TierPrice Block in Magento2uiComponent Form. How to show data from DB tableMagento 2 - insertListing ui componentMagento2. How to create custom form for email sending in admin GRID form?How to pass data to another ui components DataProviderMagento2 insertListing inside fieldsetMagento 2 UI grid non db dataprovider and pagination issueIn Magento2, how to get checked checkboxes values in uicomponent grid in frontend?Magento 2: form & grid components on one pageLoading Product Grid In UI Form But not able to post data to controller
Ask for a paid taxi in order to arrive as early as possible for an interview within the city
Is there any practical application for performing a double Fourier transform? ...or an inverse Fourier transform on a time-domain input?
Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")
If all stars rotate, why was there a theory developed, that requires non-rotating stars?
Why aren't RCS openings an issue for spacecraft heat shields?
A square inside an equilateral triangle
Avoiding racist tropes in fantasy
Do ability scores have any effect on casting the Wish spell?
Why is observed clock rate < 3MHz on Arduino Uno?
Science fiction short story where aliens contact a drunk about Earth's impending destruction
What is wrong about this application of Kirchhoffs Current Law?
Are illustrations in novels frowned upon?
Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?
How should I face my manager if I make a mistake because a senior coworker explained something incorrectly to me?
What does it mean to have a subnet mask /32?
Efficiently pathfinding many flocking enemies around obstacles
Is it possible to create a golf ball sized star?
Can I switch to third-person while not in 'town' in Destiny 2?
Can you help me understand Modes from the aspect of chord changes?
If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?
Heyacrazy: "LMI"
Church Booleans
Three Singles in Three Clubs
Fancy String Replace
Magento2 send ID insertListing to grid
How can i rewrite TierPrice Block in Magento2uiComponent Form. How to show data from DB tableMagento 2 - insertListing ui componentMagento2. How to create custom form for email sending in admin GRID form?How to pass data to another ui components DataProviderMagento2 insertListing inside fieldsetMagento 2 UI grid non db dataprovider and pagination issueIn Magento2, how to get checked checkboxes values in uicomponent grid in frontend?Magento 2: form & grid components on one pageLoading Product Grid In UI Form But not able to post data to controller
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How can i send a id from my form to a insert Listing grid?
What i want to do, is in my form i load a grid with insert Listing.
In this grid i want all results with id of the form.
<insertListing name="insertlisting_colors_one">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="imports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.provider :data.spd_id</item>
</item>
<item name="ns" xsi:type="string">colors_one_grid</item>
</item>
</argument>
</insertListing>
Below is the code in the grid
<item name="filter_url_params" xsi:type="array">
<item name="color_amount" xsi:type="string">1</item>
<item name="spd_id" xsi:type="string">$ $.parentName .spd_id</item>
</item>
magento2 uicomponent
add a comment |
How can i send a id from my form to a insert Listing grid?
What i want to do, is in my form i load a grid with insert Listing.
In this grid i want all results with id of the form.
<insertListing name="insertlisting_colors_one">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="imports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.provider :data.spd_id</item>
</item>
<item name="ns" xsi:type="string">colors_one_grid</item>
</item>
</argument>
</insertListing>
Below is the code in the grid
<item name="filter_url_params" xsi:type="array">
<item name="color_amount" xsi:type="string">1</item>
<item name="spd_id" xsi:type="string">$ $.parentName .spd_id</item>
</item>
magento2 uicomponent
1
Do you get any solution for this... or anybody else.. I am also facing same issue... anyone can help?
– Ashish Raj
Sep 27 '18 at 4:00
add a comment |
How can i send a id from my form to a insert Listing grid?
What i want to do, is in my form i load a grid with insert Listing.
In this grid i want all results with id of the form.
<insertListing name="insertlisting_colors_one">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="imports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.provider :data.spd_id</item>
</item>
<item name="ns" xsi:type="string">colors_one_grid</item>
</item>
</argument>
</insertListing>
Below is the code in the grid
<item name="filter_url_params" xsi:type="array">
<item name="color_amount" xsi:type="string">1</item>
<item name="spd_id" xsi:type="string">$ $.parentName .spd_id</item>
</item>
magento2 uicomponent
How can i send a id from my form to a insert Listing grid?
What i want to do, is in my form i load a grid with insert Listing.
In this grid i want all results with id of the form.
<insertListing name="insertlisting_colors_one">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="imports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.provider :data.spd_id</item>
</item>
<item name="ns" xsi:type="string">colors_one_grid</item>
</item>
</argument>
</insertListing>
Below is the code in the grid
<item name="filter_url_params" xsi:type="array">
<item name="color_amount" xsi:type="string">1</item>
<item name="spd_id" xsi:type="string">$ $.parentName .spd_id</item>
</item>
magento2 uicomponent
magento2 uicomponent
asked Dec 5 '17 at 13:49
JohanJohan
1761 silver badge13 bronze badges
1761 silver badge13 bronze badges
1
Do you get any solution for this... or anybody else.. I am also facing same issue... anyone can help?
– Ashish Raj
Sep 27 '18 at 4:00
add a comment |
1
Do you get any solution for this... or anybody else.. I am also facing same issue... anyone can help?
– Ashish Raj
Sep 27 '18 at 4:00
1
1
Do you get any solution for this... or anybody else.. I am also facing same issue... anyone can help?
– Ashish Raj
Sep 27 '18 at 4:00
Do you get any solution for this... or anybody else.. I am also facing same issue... anyone can help?
– Ashish Raj
Sep 27 '18 at 4:00
add a comment |
2 Answers
2
active
oldest
votes
You need to set a value for the parameter render_url on the insertListing and then update this URL inside of your Data Provider. It is necessary to perform this action twice since you will need to have one Data Provider for your form component and another one specific for the listing component.
1 - Correct declaration of the insertListing component:
(Vendor/Module/view/adminhtml/ui_component/vendor_module_form.xml)
<insertListing name="testInsertListing">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataLinks" xsi:type="array">
<item name="imports" xsi:type="boolean">false</item>
<item name="exports" xsi:type="boolean">true</item>
</item>
<item name="autoRender" xsi:type="boolean">true</item>
<!-- the namespace attribute should be the name of the listing XML file -->
<item name="ns" xsi:type="string">vendor_module_listing</item>
<!-- This is the default render_url. We are going to update this value
in the DataProvider -->
<item name="render_url" xsi:type="url" path="mui/index/render"/>
<!-- Here we add the parameters that we want to add to the render_url. -->
<item name="filter_url_params" xsi:type="array">
<!-- You can add as many as you want -->
<item name="id" xsi:type="string">*</item>
</item>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">id</item>
</item>
</item>
</argument>
</insertListing>
2 - Add the following changes to the Data Provider of the Form page. This will change the render_url by adding the parameter "id" to the end of the URL:
(Vendor/Module/Ui/DataProvider/[path-to-your-data-provider.php])
- Add the RequestInterface class:
- Declare the attribute $request on your Data Provider class.
- Add a RequestInterface object to the __construct method; call the prepareUpdateUrl() method.
- Add the prepareUpdateUrl() to your class:
Note: do not copy/paste the entire block below on your Data Provider. Instead, cherrypick the pieces that are missing from your code
<?php use MagentoFrameworkAppRequestInterface;
use MagentoFrameworkUrlInterface;
class MyListingDataProvider extends AbstractDataProvider
protected $data;
protected $meta;
protected $collection;
protected $urlBuilder;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
UrlInterface $urlBuilder,
array $meta = [],
array $data = []
)
$this->collection = $collection;
$this->data = $data;
$this->meta = $meta;
$this->request = $request;
$this->urlBuilder = $urlBuilder;
$this->prepareUpdateUrl();
parent::__construct($name, $primaryFieldName, $requestFieldName, $this->meta, $data);
protected function prepareUpdateUrl()
$id = $this->request->getParam('id');
$this->meta = array_replace_recursive(
$this->meta,
[
'testInsertListing' =>
['arguments' => [
'data' => [
'config' => [
'render_url' => $this->urlBuilder
->getUrl('mui/index/render/id/' . $id),
'update_url' => $this->urlBuilder->getUrl('mui/index/render/id/' . $id)
]
],
]
]
]
);
//Implement the other methods you need
3 - Update your listing component. It must have a updateUrl parameter inside of the DataSource component:
(Vendor/Module/view/adminhtml/ui_component/vendor_module_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">
vendor_module_listing.module_listing_data_source
</item>
</item>
</argument>
<settings>
<spinner>vendor_module_listing_columns</spinner>
<deps>
<dep>vendor_module_listing.module_listing_data_source</dep>
</deps>
</settings>
<dataSource name="module_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">VendorModuleUiDataProvider[name-of-your-listing-data-provider-class]</argument>
<argument name="name" xsi:type="string">module_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="indexField" xsi:type="string">id</item>
</item>
<!-- fields to be added to the URL when retrieving the data -->
<item name="filter_url_params" xsi:type="array">
<item name="id" xsi:type="string">*</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<columns name="vendor_module_listing_columns">
<!-- Declare your columns here -->
</columns>
</listing>
4 - Update your Listing Data Provider to change the updateUrl on the above listing component
(Vendor/Module/Ui/DataProvider/[path-to-your-LISTING-data-provider.php])
Note: do not copy/paste the entire block below on your Data Provider. Instead, cherrypick the pieces that are missing from your code
<?php
use MagentoFrameworkAppRequestInterface;
class MyListingDataProvider extends AbstractDataProvider
protected $request;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
array $meta = [],
array $data = []
)
$this->collection = $collection;
$this->request = $request;
$this->data = $data;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->prepareUpdateUrl();
protected function prepareUpdateUrl()
if (!isset($this->data['config']['filter_url_params']))
return;
foreach ($this->data['config']['filter_url_params']
as $paramName => $paramValue)
if ('*' == $paramValue)
$paramValue = $this->request->getParam($paramName);
if ($paramValue)
$this->data['config']['update_url'] = sprintf(
'%s%s/%s/',
$this->data['config']['update_url'],
$paramName,
$paramValue
);
//Get the parameter "id" inside of the getData() method:
public function getData()
$item_id = $this->request->getParam('id');
//Apply a filter to your collection using $item_id
/**
Return your data in the appropriate format
$totalRecords should be an integer
$items should be an array
*/
return array('totalRecords' => $totalRecords, 'items' => $items);
Let me know if you still have any problems. I may not be able to answer on the comments but I can update my answer.
add a comment |
For add insert listing by param of parent ui-component we can use below code.
Here externalProvider
tag is for add source provider of the listing which we are inserting.
Here imports
tag is used for import param of the current form data source
Here exports
tag is used for export the current form data params to the listing which going to be insert.
<insertListing name="insertlisting_colors_one">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="ns" xsi:type="string">colors_one_grid</item>
<item name="externalProvider" xsi:type="string">colors_one_listing.colors_one_listing_data_source</item><!-- your insert listing data provider source -->
<item name="imports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.provider :data.spd_id</item>
</item>
<item name="exports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.externalProvider :params.spd_id</item>
</item>
</item>
</argument>
</insertListing>
Add join with relevant column to the current collection for make it use in filter the data provider of inserted listing.
In the data provider add filter for this param:
$collection->addFieldToFilter('spd_id', $this->request->getParam('spd_id'));
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f204548%2fmagento2-send-id-insertlisting-to-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to set a value for the parameter render_url on the insertListing and then update this URL inside of your Data Provider. It is necessary to perform this action twice since you will need to have one Data Provider for your form component and another one specific for the listing component.
1 - Correct declaration of the insertListing component:
(Vendor/Module/view/adminhtml/ui_component/vendor_module_form.xml)
<insertListing name="testInsertListing">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataLinks" xsi:type="array">
<item name="imports" xsi:type="boolean">false</item>
<item name="exports" xsi:type="boolean">true</item>
</item>
<item name="autoRender" xsi:type="boolean">true</item>
<!-- the namespace attribute should be the name of the listing XML file -->
<item name="ns" xsi:type="string">vendor_module_listing</item>
<!-- This is the default render_url. We are going to update this value
in the DataProvider -->
<item name="render_url" xsi:type="url" path="mui/index/render"/>
<!-- Here we add the parameters that we want to add to the render_url. -->
<item name="filter_url_params" xsi:type="array">
<!-- You can add as many as you want -->
<item name="id" xsi:type="string">*</item>
</item>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">id</item>
</item>
</item>
</argument>
</insertListing>
2 - Add the following changes to the Data Provider of the Form page. This will change the render_url by adding the parameter "id" to the end of the URL:
(Vendor/Module/Ui/DataProvider/[path-to-your-data-provider.php])
- Add the RequestInterface class:
- Declare the attribute $request on your Data Provider class.
- Add a RequestInterface object to the __construct method; call the prepareUpdateUrl() method.
- Add the prepareUpdateUrl() to your class:
Note: do not copy/paste the entire block below on your Data Provider. Instead, cherrypick the pieces that are missing from your code
<?php use MagentoFrameworkAppRequestInterface;
use MagentoFrameworkUrlInterface;
class MyListingDataProvider extends AbstractDataProvider
protected $data;
protected $meta;
protected $collection;
protected $urlBuilder;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
UrlInterface $urlBuilder,
array $meta = [],
array $data = []
)
$this->collection = $collection;
$this->data = $data;
$this->meta = $meta;
$this->request = $request;
$this->urlBuilder = $urlBuilder;
$this->prepareUpdateUrl();
parent::__construct($name, $primaryFieldName, $requestFieldName, $this->meta, $data);
protected function prepareUpdateUrl()
$id = $this->request->getParam('id');
$this->meta = array_replace_recursive(
$this->meta,
[
'testInsertListing' =>
['arguments' => [
'data' => [
'config' => [
'render_url' => $this->urlBuilder
->getUrl('mui/index/render/id/' . $id),
'update_url' => $this->urlBuilder->getUrl('mui/index/render/id/' . $id)
]
],
]
]
]
);
//Implement the other methods you need
3 - Update your listing component. It must have a updateUrl parameter inside of the DataSource component:
(Vendor/Module/view/adminhtml/ui_component/vendor_module_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">
vendor_module_listing.module_listing_data_source
</item>
</item>
</argument>
<settings>
<spinner>vendor_module_listing_columns</spinner>
<deps>
<dep>vendor_module_listing.module_listing_data_source</dep>
</deps>
</settings>
<dataSource name="module_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">VendorModuleUiDataProvider[name-of-your-listing-data-provider-class]</argument>
<argument name="name" xsi:type="string">module_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="indexField" xsi:type="string">id</item>
</item>
<!-- fields to be added to the URL when retrieving the data -->
<item name="filter_url_params" xsi:type="array">
<item name="id" xsi:type="string">*</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<columns name="vendor_module_listing_columns">
<!-- Declare your columns here -->
</columns>
</listing>
4 - Update your Listing Data Provider to change the updateUrl on the above listing component
(Vendor/Module/Ui/DataProvider/[path-to-your-LISTING-data-provider.php])
Note: do not copy/paste the entire block below on your Data Provider. Instead, cherrypick the pieces that are missing from your code
<?php
use MagentoFrameworkAppRequestInterface;
class MyListingDataProvider extends AbstractDataProvider
protected $request;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
array $meta = [],
array $data = []
)
$this->collection = $collection;
$this->request = $request;
$this->data = $data;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->prepareUpdateUrl();
protected function prepareUpdateUrl()
if (!isset($this->data['config']['filter_url_params']))
return;
foreach ($this->data['config']['filter_url_params']
as $paramName => $paramValue)
if ('*' == $paramValue)
$paramValue = $this->request->getParam($paramName);
if ($paramValue)
$this->data['config']['update_url'] = sprintf(
'%s%s/%s/',
$this->data['config']['update_url'],
$paramName,
$paramValue
);
//Get the parameter "id" inside of the getData() method:
public function getData()
$item_id = $this->request->getParam('id');
//Apply a filter to your collection using $item_id
/**
Return your data in the appropriate format
$totalRecords should be an integer
$items should be an array
*/
return array('totalRecords' => $totalRecords, 'items' => $items);
Let me know if you still have any problems. I may not be able to answer on the comments but I can update my answer.
add a comment |
You need to set a value for the parameter render_url on the insertListing and then update this URL inside of your Data Provider. It is necessary to perform this action twice since you will need to have one Data Provider for your form component and another one specific for the listing component.
1 - Correct declaration of the insertListing component:
(Vendor/Module/view/adminhtml/ui_component/vendor_module_form.xml)
<insertListing name="testInsertListing">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataLinks" xsi:type="array">
<item name="imports" xsi:type="boolean">false</item>
<item name="exports" xsi:type="boolean">true</item>
</item>
<item name="autoRender" xsi:type="boolean">true</item>
<!-- the namespace attribute should be the name of the listing XML file -->
<item name="ns" xsi:type="string">vendor_module_listing</item>
<!-- This is the default render_url. We are going to update this value
in the DataProvider -->
<item name="render_url" xsi:type="url" path="mui/index/render"/>
<!-- Here we add the parameters that we want to add to the render_url. -->
<item name="filter_url_params" xsi:type="array">
<!-- You can add as many as you want -->
<item name="id" xsi:type="string">*</item>
</item>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">id</item>
</item>
</item>
</argument>
</insertListing>
2 - Add the following changes to the Data Provider of the Form page. This will change the render_url by adding the parameter "id" to the end of the URL:
(Vendor/Module/Ui/DataProvider/[path-to-your-data-provider.php])
- Add the RequestInterface class:
- Declare the attribute $request on your Data Provider class.
- Add a RequestInterface object to the __construct method; call the prepareUpdateUrl() method.
- Add the prepareUpdateUrl() to your class:
Note: do not copy/paste the entire block below on your Data Provider. Instead, cherrypick the pieces that are missing from your code
<?php use MagentoFrameworkAppRequestInterface;
use MagentoFrameworkUrlInterface;
class MyListingDataProvider extends AbstractDataProvider
protected $data;
protected $meta;
protected $collection;
protected $urlBuilder;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
UrlInterface $urlBuilder,
array $meta = [],
array $data = []
)
$this->collection = $collection;
$this->data = $data;
$this->meta = $meta;
$this->request = $request;
$this->urlBuilder = $urlBuilder;
$this->prepareUpdateUrl();
parent::__construct($name, $primaryFieldName, $requestFieldName, $this->meta, $data);
protected function prepareUpdateUrl()
$id = $this->request->getParam('id');
$this->meta = array_replace_recursive(
$this->meta,
[
'testInsertListing' =>
['arguments' => [
'data' => [
'config' => [
'render_url' => $this->urlBuilder
->getUrl('mui/index/render/id/' . $id),
'update_url' => $this->urlBuilder->getUrl('mui/index/render/id/' . $id)
]
],
]
]
]
);
//Implement the other methods you need
3 - Update your listing component. It must have a updateUrl parameter inside of the DataSource component:
(Vendor/Module/view/adminhtml/ui_component/vendor_module_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">
vendor_module_listing.module_listing_data_source
</item>
</item>
</argument>
<settings>
<spinner>vendor_module_listing_columns</spinner>
<deps>
<dep>vendor_module_listing.module_listing_data_source</dep>
</deps>
</settings>
<dataSource name="module_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">VendorModuleUiDataProvider[name-of-your-listing-data-provider-class]</argument>
<argument name="name" xsi:type="string">module_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="indexField" xsi:type="string">id</item>
</item>
<!-- fields to be added to the URL when retrieving the data -->
<item name="filter_url_params" xsi:type="array">
<item name="id" xsi:type="string">*</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<columns name="vendor_module_listing_columns">
<!-- Declare your columns here -->
</columns>
</listing>
4 - Update your Listing Data Provider to change the updateUrl on the above listing component
(Vendor/Module/Ui/DataProvider/[path-to-your-LISTING-data-provider.php])
Note: do not copy/paste the entire block below on your Data Provider. Instead, cherrypick the pieces that are missing from your code
<?php
use MagentoFrameworkAppRequestInterface;
class MyListingDataProvider extends AbstractDataProvider
protected $request;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
array $meta = [],
array $data = []
)
$this->collection = $collection;
$this->request = $request;
$this->data = $data;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->prepareUpdateUrl();
protected function prepareUpdateUrl()
if (!isset($this->data['config']['filter_url_params']))
return;
foreach ($this->data['config']['filter_url_params']
as $paramName => $paramValue)
if ('*' == $paramValue)
$paramValue = $this->request->getParam($paramName);
if ($paramValue)
$this->data['config']['update_url'] = sprintf(
'%s%s/%s/',
$this->data['config']['update_url'],
$paramName,
$paramValue
);
//Get the parameter "id" inside of the getData() method:
public function getData()
$item_id = $this->request->getParam('id');
//Apply a filter to your collection using $item_id
/**
Return your data in the appropriate format
$totalRecords should be an integer
$items should be an array
*/
return array('totalRecords' => $totalRecords, 'items' => $items);
Let me know if you still have any problems. I may not be able to answer on the comments but I can update my answer.
add a comment |
You need to set a value for the parameter render_url on the insertListing and then update this URL inside of your Data Provider. It is necessary to perform this action twice since you will need to have one Data Provider for your form component and another one specific for the listing component.
1 - Correct declaration of the insertListing component:
(Vendor/Module/view/adminhtml/ui_component/vendor_module_form.xml)
<insertListing name="testInsertListing">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataLinks" xsi:type="array">
<item name="imports" xsi:type="boolean">false</item>
<item name="exports" xsi:type="boolean">true</item>
</item>
<item name="autoRender" xsi:type="boolean">true</item>
<!-- the namespace attribute should be the name of the listing XML file -->
<item name="ns" xsi:type="string">vendor_module_listing</item>
<!-- This is the default render_url. We are going to update this value
in the DataProvider -->
<item name="render_url" xsi:type="url" path="mui/index/render"/>
<!-- Here we add the parameters that we want to add to the render_url. -->
<item name="filter_url_params" xsi:type="array">
<!-- You can add as many as you want -->
<item name="id" xsi:type="string">*</item>
</item>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">id</item>
</item>
</item>
</argument>
</insertListing>
2 - Add the following changes to the Data Provider of the Form page. This will change the render_url by adding the parameter "id" to the end of the URL:
(Vendor/Module/Ui/DataProvider/[path-to-your-data-provider.php])
- Add the RequestInterface class:
- Declare the attribute $request on your Data Provider class.
- Add a RequestInterface object to the __construct method; call the prepareUpdateUrl() method.
- Add the prepareUpdateUrl() to your class:
Note: do not copy/paste the entire block below on your Data Provider. Instead, cherrypick the pieces that are missing from your code
<?php use MagentoFrameworkAppRequestInterface;
use MagentoFrameworkUrlInterface;
class MyListingDataProvider extends AbstractDataProvider
protected $data;
protected $meta;
protected $collection;
protected $urlBuilder;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
UrlInterface $urlBuilder,
array $meta = [],
array $data = []
)
$this->collection = $collection;
$this->data = $data;
$this->meta = $meta;
$this->request = $request;
$this->urlBuilder = $urlBuilder;
$this->prepareUpdateUrl();
parent::__construct($name, $primaryFieldName, $requestFieldName, $this->meta, $data);
protected function prepareUpdateUrl()
$id = $this->request->getParam('id');
$this->meta = array_replace_recursive(
$this->meta,
[
'testInsertListing' =>
['arguments' => [
'data' => [
'config' => [
'render_url' => $this->urlBuilder
->getUrl('mui/index/render/id/' . $id),
'update_url' => $this->urlBuilder->getUrl('mui/index/render/id/' . $id)
]
],
]
]
]
);
//Implement the other methods you need
3 - Update your listing component. It must have a updateUrl parameter inside of the DataSource component:
(Vendor/Module/view/adminhtml/ui_component/vendor_module_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">
vendor_module_listing.module_listing_data_source
</item>
</item>
</argument>
<settings>
<spinner>vendor_module_listing_columns</spinner>
<deps>
<dep>vendor_module_listing.module_listing_data_source</dep>
</deps>
</settings>
<dataSource name="module_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">VendorModuleUiDataProvider[name-of-your-listing-data-provider-class]</argument>
<argument name="name" xsi:type="string">module_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="indexField" xsi:type="string">id</item>
</item>
<!-- fields to be added to the URL when retrieving the data -->
<item name="filter_url_params" xsi:type="array">
<item name="id" xsi:type="string">*</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<columns name="vendor_module_listing_columns">
<!-- Declare your columns here -->
</columns>
</listing>
4 - Update your Listing Data Provider to change the updateUrl on the above listing component
(Vendor/Module/Ui/DataProvider/[path-to-your-LISTING-data-provider.php])
Note: do not copy/paste the entire block below on your Data Provider. Instead, cherrypick the pieces that are missing from your code
<?php
use MagentoFrameworkAppRequestInterface;
class MyListingDataProvider extends AbstractDataProvider
protected $request;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
array $meta = [],
array $data = []
)
$this->collection = $collection;
$this->request = $request;
$this->data = $data;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->prepareUpdateUrl();
protected function prepareUpdateUrl()
if (!isset($this->data['config']['filter_url_params']))
return;
foreach ($this->data['config']['filter_url_params']
as $paramName => $paramValue)
if ('*' == $paramValue)
$paramValue = $this->request->getParam($paramName);
if ($paramValue)
$this->data['config']['update_url'] = sprintf(
'%s%s/%s/',
$this->data['config']['update_url'],
$paramName,
$paramValue
);
//Get the parameter "id" inside of the getData() method:
public function getData()
$item_id = $this->request->getParam('id');
//Apply a filter to your collection using $item_id
/**
Return your data in the appropriate format
$totalRecords should be an integer
$items should be an array
*/
return array('totalRecords' => $totalRecords, 'items' => $items);
Let me know if you still have any problems. I may not be able to answer on the comments but I can update my answer.
You need to set a value for the parameter render_url on the insertListing and then update this URL inside of your Data Provider. It is necessary to perform this action twice since you will need to have one Data Provider for your form component and another one specific for the listing component.
1 - Correct declaration of the insertListing component:
(Vendor/Module/view/adminhtml/ui_component/vendor_module_form.xml)
<insertListing name="testInsertListing">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataLinks" xsi:type="array">
<item name="imports" xsi:type="boolean">false</item>
<item name="exports" xsi:type="boolean">true</item>
</item>
<item name="autoRender" xsi:type="boolean">true</item>
<!-- the namespace attribute should be the name of the listing XML file -->
<item name="ns" xsi:type="string">vendor_module_listing</item>
<!-- This is the default render_url. We are going to update this value
in the DataProvider -->
<item name="render_url" xsi:type="url" path="mui/index/render"/>
<!-- Here we add the parameters that we want to add to the render_url. -->
<item name="filter_url_params" xsi:type="array">
<!-- You can add as many as you want -->
<item name="id" xsi:type="string">*</item>
</item>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">id</item>
</item>
</item>
</argument>
</insertListing>
2 - Add the following changes to the Data Provider of the Form page. This will change the render_url by adding the parameter "id" to the end of the URL:
(Vendor/Module/Ui/DataProvider/[path-to-your-data-provider.php])
- Add the RequestInterface class:
- Declare the attribute $request on your Data Provider class.
- Add a RequestInterface object to the __construct method; call the prepareUpdateUrl() method.
- Add the prepareUpdateUrl() to your class:
Note: do not copy/paste the entire block below on your Data Provider. Instead, cherrypick the pieces that are missing from your code
<?php use MagentoFrameworkAppRequestInterface;
use MagentoFrameworkUrlInterface;
class MyListingDataProvider extends AbstractDataProvider
protected $data;
protected $meta;
protected $collection;
protected $urlBuilder;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
UrlInterface $urlBuilder,
array $meta = [],
array $data = []
)
$this->collection = $collection;
$this->data = $data;
$this->meta = $meta;
$this->request = $request;
$this->urlBuilder = $urlBuilder;
$this->prepareUpdateUrl();
parent::__construct($name, $primaryFieldName, $requestFieldName, $this->meta, $data);
protected function prepareUpdateUrl()
$id = $this->request->getParam('id');
$this->meta = array_replace_recursive(
$this->meta,
[
'testInsertListing' =>
['arguments' => [
'data' => [
'config' => [
'render_url' => $this->urlBuilder
->getUrl('mui/index/render/id/' . $id),
'update_url' => $this->urlBuilder->getUrl('mui/index/render/id/' . $id)
]
],
]
]
]
);
//Implement the other methods you need
3 - Update your listing component. It must have a updateUrl parameter inside of the DataSource component:
(Vendor/Module/view/adminhtml/ui_component/vendor_module_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">
vendor_module_listing.module_listing_data_source
</item>
</item>
</argument>
<settings>
<spinner>vendor_module_listing_columns</spinner>
<deps>
<dep>vendor_module_listing.module_listing_data_source</dep>
</deps>
</settings>
<dataSource name="module_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">VendorModuleUiDataProvider[name-of-your-listing-data-provider-class]</argument>
<argument name="name" xsi:type="string">module_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="indexField" xsi:type="string">id</item>
</item>
<!-- fields to be added to the URL when retrieving the data -->
<item name="filter_url_params" xsi:type="array">
<item name="id" xsi:type="string">*</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<columns name="vendor_module_listing_columns">
<!-- Declare your columns here -->
</columns>
</listing>
4 - Update your Listing Data Provider to change the updateUrl on the above listing component
(Vendor/Module/Ui/DataProvider/[path-to-your-LISTING-data-provider.php])
Note: do not copy/paste the entire block below on your Data Provider. Instead, cherrypick the pieces that are missing from your code
<?php
use MagentoFrameworkAppRequestInterface;
class MyListingDataProvider extends AbstractDataProvider
protected $request;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
array $meta = [],
array $data = []
)
$this->collection = $collection;
$this->request = $request;
$this->data = $data;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->prepareUpdateUrl();
protected function prepareUpdateUrl()
if (!isset($this->data['config']['filter_url_params']))
return;
foreach ($this->data['config']['filter_url_params']
as $paramName => $paramValue)
if ('*' == $paramValue)
$paramValue = $this->request->getParam($paramName);
if ($paramValue)
$this->data['config']['update_url'] = sprintf(
'%s%s/%s/',
$this->data['config']['update_url'],
$paramName,
$paramValue
);
//Get the parameter "id" inside of the getData() method:
public function getData()
$item_id = $this->request->getParam('id');
//Apply a filter to your collection using $item_id
/**
Return your data in the appropriate format
$totalRecords should be an integer
$items should be an array
*/
return array('totalRecords' => $totalRecords, 'items' => $items);
Let me know if you still have any problems. I may not be able to answer on the comments but I can update my answer.
answered Sep 29 '18 at 7:02
Andresa KrulAndresa Krul
111 bronze badge
111 bronze badge
add a comment |
add a comment |
For add insert listing by param of parent ui-component we can use below code.
Here externalProvider
tag is for add source provider of the listing which we are inserting.
Here imports
tag is used for import param of the current form data source
Here exports
tag is used for export the current form data params to the listing which going to be insert.
<insertListing name="insertlisting_colors_one">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="ns" xsi:type="string">colors_one_grid</item>
<item name="externalProvider" xsi:type="string">colors_one_listing.colors_one_listing_data_source</item><!-- your insert listing data provider source -->
<item name="imports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.provider :data.spd_id</item>
</item>
<item name="exports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.externalProvider :params.spd_id</item>
</item>
</item>
</argument>
</insertListing>
Add join with relevant column to the current collection for make it use in filter the data provider of inserted listing.
In the data provider add filter for this param:
$collection->addFieldToFilter('spd_id', $this->request->getParam('spd_id'));
add a comment |
For add insert listing by param of parent ui-component we can use below code.
Here externalProvider
tag is for add source provider of the listing which we are inserting.
Here imports
tag is used for import param of the current form data source
Here exports
tag is used for export the current form data params to the listing which going to be insert.
<insertListing name="insertlisting_colors_one">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="ns" xsi:type="string">colors_one_grid</item>
<item name="externalProvider" xsi:type="string">colors_one_listing.colors_one_listing_data_source</item><!-- your insert listing data provider source -->
<item name="imports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.provider :data.spd_id</item>
</item>
<item name="exports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.externalProvider :params.spd_id</item>
</item>
</item>
</argument>
</insertListing>
Add join with relevant column to the current collection for make it use in filter the data provider of inserted listing.
In the data provider add filter for this param:
$collection->addFieldToFilter('spd_id', $this->request->getParam('spd_id'));
add a comment |
For add insert listing by param of parent ui-component we can use below code.
Here externalProvider
tag is for add source provider of the listing which we are inserting.
Here imports
tag is used for import param of the current form data source
Here exports
tag is used for export the current form data params to the listing which going to be insert.
<insertListing name="insertlisting_colors_one">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="ns" xsi:type="string">colors_one_grid</item>
<item name="externalProvider" xsi:type="string">colors_one_listing.colors_one_listing_data_source</item><!-- your insert listing data provider source -->
<item name="imports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.provider :data.spd_id</item>
</item>
<item name="exports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.externalProvider :params.spd_id</item>
</item>
</item>
</argument>
</insertListing>
Add join with relevant column to the current collection for make it use in filter the data provider of inserted listing.
In the data provider add filter for this param:
$collection->addFieldToFilter('spd_id', $this->request->getParam('spd_id'));
For add insert listing by param of parent ui-component we can use below code.
Here externalProvider
tag is for add source provider of the listing which we are inserting.
Here imports
tag is used for import param of the current form data source
Here exports
tag is used for export the current form data params to the listing which going to be insert.
<insertListing name="insertlisting_colors_one">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="ns" xsi:type="string">colors_one_grid</item>
<item name="externalProvider" xsi:type="string">colors_one_listing.colors_one_listing_data_source</item><!-- your insert listing data provider source -->
<item name="imports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.provider :data.spd_id</item>
</item>
<item name="exports" xsi:type="array">
<item name="spd_id" xsi:type="string">$ $.externalProvider :params.spd_id</item>
</item>
</item>
</argument>
</insertListing>
Add join with relevant column to the current collection for make it use in filter the data provider of inserted listing.
In the data provider add filter for this param:
$collection->addFieldToFilter('spd_id', $this->request->getParam('spd_id'));
edited Oct 5 '18 at 6:13
answered Oct 5 '18 at 6:06
Ashish RajAshish Raj
6621 gold badge7 silver badges24 bronze badges
6621 gold badge7 silver badges24 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f204548%2fmagento2-send-id-insertlisting-to-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Do you get any solution for this... or anybody else.. I am also facing same issue... anyone can help?
– Ashish Raj
Sep 27 '18 at 4:00