In Magento 2.2.5, I have a custom agrid. It has edit option and url parameters.
I need to create another grid in the edit page based on the url parameter. ie., I need to filter the custom grid based on the url parameter.
Note: Am not using ui component to create grid.
-
Could you please add your ui component file ?Dharmendra Jadav– Dharmendra Jadav2018年10月03日 06:30:37 +00:00Commented Oct 3, 2018 at 6:30
2 Answers 2
Please find below line in your ui component file.
<item name="update_url" xsi:type="url" path="mui/index/render"/>
After that add below code after that line.
<item name="filter_url_params" xsi:type="array">
<item name="id" xsi:type="boolean">1</item>
</item>
You can get filter data in your grid.
Still you have any query let me know.
-
Thanks for your response. It is not in ui component.Saravanan DS– Saravanan DS2018年10月03日 07:44:43 +00:00Commented Oct 3, 2018 at 7:44
-
where you need it ?Dharmendra Jadav– Dharmendra Jadav2018年10月03日 07:45:51 +00:00Commented Oct 3, 2018 at 7:45
-
I mean I am not using Ui component to create this grid. I am using normal blocks.Saravanan DS– Saravanan DS2018年10月03日 07:46:34 +00:00Commented Oct 3, 2018 at 7:46
-
could you please post your code?Dharmendra Jadav– Dharmendra Jadav2018年10月03日 07:47:16 +00:00Commented Oct 3, 2018 at 7:47
-
please find my code here pastebin.com/z9aww705Saravanan DS– Saravanan DS2018年10月03日 07:53:50 +00:00Commented Oct 3, 2018 at 7:53
Reference: Marius answer
In the layout xml file, change the Core Grid block to Custom Grid Block like below:
<block class="Magento\Backend\Block\Widget\Grid" name="apptha_merchant_post_grid.grid" as="grid">
Change this to:
<block class="Apptha\Customergroup\Block\Adminhtml\Response" name="apptha_merchant_post_grid.grid" as="grid">
Code of the Block File is:
<?php
namespace Apptha\Customergroup\Block\Adminhtml;
class Response extends \Magento\Backend\Block\Widget\Grid
{
public function _construct()
{
parent::_construct();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$referenceId = $objectManager->create('Apptha\Customergroup\Model\Deal')
->load($this->getRequest()->getParam('id'))->getData("reference_id");
//We'll get the Grid collection here by using this: $this->getCollection()
//We can filter it like addFieldToFilter method
//Here I am filtering grid collection using reference id
$this->getCollection()->addFieldToFilter('reference_id', array('eq' => $referenceId));
}
}